objective-ccxcodefunctionmacros

What is the difference between ABS(A) and abs(int)?


I am baffled in the difference of these two functions in Xcode: ABS(A) and abs(int). I can't seem to find any explanation online. 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.

http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer


Solution

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