Mail Archives: djgpp/1992/09/30/13:54:35
>
>There are different standard library functions adapted to the special
>types of variables:
>
> abs() returns type int,
> labs() (not implemented on every system) returns long int,
> fabs() returns float (sometimes double)
>
>
>You will have to include the correct header files "stdlib.h" or
>"math.h" (besides "stdio.h" of course) to be able to use them.
>
> Robert Wolter
> wolter AT wrcm2 DOT urz DOT uni-wuppertal DOT de
>
ABS works better as a macro -- then the compiler can determine type dynamically.
#define ABS(x) ((x) < 0 ? -x : x)
should work, unless I'm missing some obscure ANSI type promotion problem. If
you want to get fancy, you can use typeof with GCC to coerce 0 to the proper
type, but I'm not at all sure it's necessary.
- Raw text -