So maybe the ESP32 core doesn't have this macro.
https://github.com/arduino/reference-en/issues/362#issuecomment-478540338So maybe the ESP32 core doesn't have this macro.
I had a peek at the ESP32's "Arduino.h" file, it uses the same macro.
The weird thing is, the Arduino core on ESP32 has an abs() macro as well:https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Arduino.h#L76So there is probably a bug in the Arduino core for ESP32 here, where it isn't using the "Arduino-ified" abs() macro for some reason.
The standard library's abs() doesn't process float data types.
(since C++17)float abs( float arg ); (1) double abs( double arg );
std::abs(float), std::fabs, std::fabsf, std::fabslC++Numerics libraryCommon mathematical functionsDefined in header <cmath>Defined in header <cstdlib>(since C++17)float abs( float arg );(1) double abs( double arg );(2) long double abs( long double arg );(3) Defined in header <cmath>(4) float fabs ( float arg );float fabsf( float arg );(since C++11)double fabs ( double arg );(5) (6) long double fabs ( long double arg );long double fabsl( long double arg );(since C++11)double fabs ( IntegralType arg );(7) (since C++11)
// undefine stdlib's abs if encountered#ifdef abs#undef abs#endif#define abs(x) ((x)>0?(x):-(x))
Looks like projectgus's pull request on Github also solves the issue, just by calling on:Code: [Select]using std::abs;...in the "Arduino.h" file and deleting the Arduino macro. This redefines abs() using the C++ standard library function.
C++11 and C++14 also have std::abs just for ints and std::fabs and std::fabsf for floats !Just C++17 has std::abs both for ints and fps...but does Arduino actually use C++17 ...?
Yes, it's really confusing. I was also wondering why simply adding the "using std::abs;" line, allows the abs() function to work with floats, although the ESP32 is using C++11 (and not C++17).After some investigation, I believe that the C++11's <cmath> file which is included in "Arduino.h", undefines the "abs" macro and redefines it as an overloaded function "std::abs" for a number of data types including floats.The "using std::abs;" line allows "abs" to be used in lieu of any predefined macros, so that it isn't necessary to call "std::abs" in your sketch, but simply use "abs" instead.
it appears as if gpp already features the std::abs() for fp since C14 or even 11, opposite to C++ standards only since 17https://gcc.godbolt.org/z/Flkq60https://en.cppreference.com/w/cpp/numeric/math/fabshttps://github.com/espressif/esp-idf/issues/3405#issuecomment-489480050