diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index e645743b2..8e4b97f3e 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -92,6 +92,7 @@ void loop( void ) ; #include "wiring_shift.h" #include "WInterrupts.h" +#ifndef __cplusplus // undefine stdlib's abs if encountered #ifdef abs #undef abs @@ -100,8 +101,22 @@ void loop( void ) ; #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#else + template + auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) + { + return (b < a) ? b : a; + } + + template + auto max(const T& a, const L& b) -> decltype((a < b) ? b : a) + { + return (a < b) ? b : a; + } +#endif + +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) #define sq(x) ((x)*(x))