1 
2 /* @(#)z_fabs.c 1.0 98/08/13 */
3 
4 /*
5 FUNCTION
6        <<fabs>>, <<fabsf>>---absolute value (magnitude)
7 INDEX
8         fabs
9 INDEX
10         fabsf
11 
12 ANSI_SYNOPSIS
13         #include <math.h>
14        double fabs(double <[x]>);
15        float fabsf(float <[x]>);
16 
17 TRAD_SYNOPSIS
18         #include <math.h>
19        double fabs(<[x]>)
20        double <[x]>;
21 
22        float fabsf(<[x]>)
23        float <[x]>;
24 
25 DESCRIPTION
26 <<fabs>> and <<fabsf>> calculate
27 @tex
28 $|x|$,
29 @end tex
30 the absolute value (magnitude) of the argument <[x]>, by direct
31 manipulation of the bit representation of <[x]>.
32 
33 RETURNS
34 The calculated value is returned.
35 
36 PORTABILITY
37 <<fabs>> is ANSI.
38 <<fabsf>> is an extension.
39 
40 */
41 
42 /******************************************************************
43  * Floating-Point Absolute Value
44  *
45  * Input:
46  *   x - floating-point number
47  *
48  * Output:
49  *   absolute value of x
50  *
51  * Description:
52  *   fabs computes the absolute value of a floating point number.
53  *
54  *****************************************************************/
55 
56 #include "fdlibm.h"
57 #include "zmath.h"
58 
59 #ifndef _DOUBLE_IS_32BITS
60 
61 double
62 _DEFUN (fabs, (double),
63         double x)
64 {
65   switch (numtest (x))
66     {
67       case NAN:
68         errno = EDOM;
69         return (x);
70       case INF:
71         errno = ERANGE;
72         return (x);
73       case 0:
74         return (0.0);
75       default:
76         return (x < 0.0 ? -x : x);
77     }
78 }
79 
80 #endif /* _DOUBLE_IS_32BITS */
81