On Wed, Feb 19, 2003 at 11:25:44AM +0100, Aaron Ardiri wrote:
> [Chris Apers <[EMAIL PROTECTED]> wrote:]
>> Is there an abs() function on palmos ?

There's not one in the Palm OS API, but you'll likely find that it is
supplied by your compiler's libc and/or is built into your compiler.

For example, with GCC

        int f (int x) { return abs (x); }

compiles just fine, and is optimised into a fairly optimal two
instructions (bge + neg).  That's the built-in; actually prc-tools 2.2
doesn't have abs() in its libc, but I added one to CVS some months ago
so it will be in 2.3's libc.  At that point the suitably demented will
be able to take the address of the abs() function and pass it as a
callback to other functions :-).

(I imagine CodeWarrior does something similar, but armed with only the
CW 8 demo I can't turn the optimiser up high enough to check properly.)

> #define ABS(x) (((x) < 0) ? -(x) : (x))

And in fact GCC optimises the use of this into the same two
instructions.  Yay! :-)

    John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to