arduino / ArduinoCore-API

Hardware independent layer of the Arduino cores defining the official API
https://www.arduino.cc/reference/en/
GNU Lesser General Public License v2.1
202 stars 116 forks source link

floor() and ceil() return integer values, not double (float) #81

Open tofrnr opened 7 years ago

tofrnr commented 7 years ago

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!

facchinm commented 7 years ago

Related with https://github.com/arduino/Arduino/issues/6098

cousteaulecommandant commented 6 years ago

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.

tofrnr commented 6 years ago

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.

cousteaulecommandant commented 6 years ago

...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.

matthijskooijman commented 3 years ago

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.