fabs(x) vs. (x) < 0 ? -(x) : (x)

braner at batcomputer.UUCP braner at batcomputer.UUCP
Wed Feb 11 16:32:46 AEST 1987


[]

eeexcuse me, but:

#define fabs(x) ((x) & 0x7FFFFF...)

will NOT work, and for several reasons:

The two operands ((x) and 0x7F...) are not of the same type, so one
of them has to be converted.  Then it won't work!!  Actually, it is
illegal to do '&' on a real, if I remember right.  And also, doubles
are usually longer than longs (until we get 64-bit longs :-).

You MIGHT get away with ((*(long *)&x) & 0x7FFFFFFF), but only in cases
where &x is legal, and only on machines where the sign bit of x is where
you expect it...

- Moshe Braner

THE COMPLETE FP LIB MUST BE WRITTEN IN HAND-OPTIMIZED AL!!!
ESPECIALLY SO IF YOU HAVE FP HARDWARE!!!



More information about the Comp.lang.c mailing list