Ideas for new Patterns (from LED Lamp)

The arduino reference does not mention that “abs” is limited to integers.

Leading me to think it might work on floats…

So, I wrote a short snippet of code to see:

running upon a teensy 3.6…

void loop() {
// put your main code here, to run repeatedly:
target = random(255)/255.0-3.0;
Serial.print("value: ");
Serial.println(target,4);
Serial.print("abs: ");
Serial.println(abs(target),4);
Serial.print("fabs: ");
Serial.println(fabs(target),4);
delay(1000);
}

output:

value: -2.1255
abs: 2.1255
fabs: 2.1255

Seems like abs works on floats. at least in 1.8.9 which is what this machine is running.

My microchip is esp8266.
Compiler:
ardcomp

I have the problem.

1 Like

Yes…
Different microchips count differently…

https://github.com/arduino/reference-en/issues/362

Out of the official Arduino hardware cores, the exception to this is Arduino megaAVR Boards, which does not define its own abs(). Thus, currently the only official Arduino board for which abs() does not support float is the Arduino Uno WiFi Rev2. Arduino AVR Boards, Arduino SAMD Boards, Arduino SAM Boards, and Intel Curie Boards all do define their own abs() macros.

I also checked the most popular 3rd party hardware cores and found that Teensy’s abs() does support float, while the “ESP8266 core for Arduino” and “Arduino core for the ESP32” do not.

What do you mean by “do not support”? Compile error or undefined output?
I’ve been using the code you quoted on ESP32 for over a year without apparent problems.

This is not me mean. This is a quote from the URL.
I think that “do not support” means that abs() returns an integer type.
For some microchips …

I see. So, to be clear on your chip, the pattern looked broken as a result of abs truncating the floats it was working with, correct?
From what you said, it should be broken on ESP32, but I never noticed the breakage. I’d be interested to get thatt fixed if it actually changes the visible output.
(I’ll also accept a pull request from you :slight_smile: )

Before I understood the cause of the problem, my center stoped in one of the corners every time.
I recommend just not using abs() for the float type.

Now is ok:

Got it, and which chip were you running with? (nice result by the way)

Wemos D1 mini

I don’t really like the result so far, so it has not yet been added to my selection of effects.

80 patterns

80effects

1 Like