source: trunk/libs/newlib/src/newlib/libm/mathfp/s_fabs.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

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