Cygwin: uname: add host machine tag to sysname.
[newlib-cygwin.git] / newlib / libm / mathfp / s_frexp.c
blobc0990df5f88c264f05657b7d1b53fc708825a00b
2 /* @(#)z_frexp.c 1.0 98/08/13 */
4 /*
5 FUNCTION
6 <<frexp>>, <<frexpf>>---split floating-point number
7 INDEX
8 frexp
9 INDEX
10 frexpf
12 SYNOPSIS
13 #include <math.h>
14 double frexp(double <[val]>, int *<[exp]>);
15 float frexpf(float <[val]>, int *<[exp]>);
17 DESCRIPTION
18 All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
19 <<frexp>> represents the double <[val]> as a mantissa <[m]>
20 and a power of two <[p]>. The resulting mantissa will always
21 be greater than or equal to <<0.5>>, and less than <<1.0>> (as
22 long as <[val]> is nonzero). The power of two will be stored
23 in <<*>><[exp]>.
25 @ifnottex
26 <[m]> and <[p]> are calculated so that
27 <[val]> is <[m]> times <<2>> to the power <[p]>.
28 @end ifnottex
29 @tex
30 <[m]> and <[p]> are calculated so that
31 $ val = m \times 2^p $.
32 @end tex
34 <<frexpf>> is identical, other than taking and returning
35 floats rather than doubles.
37 RETURNS
38 <<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
39 or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
41 PORTABILITY
42 <<frexp>> is ANSI.
43 <<frexpf>> is an extension.
48 /*****************************************************************
49 * frexp
51 * Input:
52 * d - floating point value
53 * exp - exponent value
55 * Output:
56 * A floating point value in the range [0.5, 1).
58 * Description:
59 * This routine breaks a floating point value into a number f and
60 * an exponent exp such that d = f * 2 ^ exp.
62 *****************************************************************/
64 #include "fdlibm.h"
65 #include "zmath.h"
67 #ifndef _DOUBLE_IS_32BITS
69 double frexp (double d, int *exp)
71 double f;
72 __uint32_t hd, ld, hf, lf;
74 /* Check for special values. */
75 switch (numtest (d))
77 case NAN:
78 case INF:
79 errno = EDOM;
80 case 0:
81 *exp = 0;
82 return (d);
85 EXTRACT_WORDS (hd, ld, d);
87 /* Get the exponent. */
88 *exp = ((hd & 0x7ff00000) >> 20) - 1022;
90 /* Get the mantissa. */
91 lf = ld;
92 hf = hd & 0x800fffff;
93 hf |= 0x3fe00000;
95 INSERT_WORDS (f, hf, lf);
97 return (f);
100 #endif /* _DOUBLE_IS_32BITS */