Go Down

Topic: abs bug (Read 981 times) previous topic - next topic


I think the abs function does not work in arduino since I still get negative values.   :o


Can you post an example of code that has problems?


You're right, abs has a bug, as do min, max, and constrain.  They'll be fixed in Arduino 0004.  In the meantime, you can put the following at the very top of your sketch (before the variable definitions).

Code: [Select]

#undef min
#undef max
#undef abs
#undef constrain
#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)))

Go Up