ArduinoCore-API
ArduinoCore-API copied to clipboard
floor() and ceil() return integer values, not double (float)
floor() and ceil() return integer values, not double (float), other than ANSI C math.h http://www.cplusplus.com/reference/cmath/ceil/ http://www.cplusplus.com/reference/cmath/floor/
(of course this issue is crucial especially for floats which are (absolutely) larger than the integer ranges)
Please make Arduino math functions comply to C standards, there is no need for divergent definitions!
Related with https://github.com/arduino/Arduino/issues/6098
As a workaround, use (floor)(x)
and (ceil)(x)
, which will not use the macro but the actual function.
Alternatively, you can create a new tab in your Arduino project with a name ending in .cpp
and put your pure C++ code there, with none of the Arduino.h
nonstandard magic.
IMO that's stupid to have to use cast functions as worksarounds, because floor() and ceil() are standard C math functions which are simply messed up by Arduino gibberish. So finally the Aduino gibberish has to be adjusted to standard C definitions, that's it, nothing else.
...well, I did say it was a workaround, didn't I? :) In any case I think Arduino.h will eventually have to be purged from macros and instead use standard C++ functions, or templated functions when no alternative exists.
I believe this is already fixed in the ArduinoCoreAPI repo. It does not define any ceil
or floor
macros, and looking through the history, it never has. It does include <math.h>
, so I think that means it effectively makes the standard library versions available.