I am baffled in the difference of this two in xcode, ABS(A) and abs(int). Cant seem to find ay explanation online as well. Which should I use? I am actually working on an accelerometer. Using ABS(A) and abs(int) gives me two different values. Using abs(int) would result in an inf value at times, while ABS(A) would give me a different value but never inf. Thanks!
http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer
abs()
works on int, meaning abs(-10.123)
would return 10
, while ABS()
is a macro from NSObjCRuntime.h
which returns a value whose type is the type of the argument.
The ABS definition from NSObjCRuntime.h is :
#define ABS(a) ({typeof(a) _a = (a); _a < 0 ? -_a : _a; })
so it returns the value with the type of the argument. abs on the other hand has the protoype
int abs (int number)
so it returns a value of type int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With