2 /* @(#)z_frexp.c 1.0 98/08/13 */
6 <<frexp>>, <<frexpf>>---split floating-point number
14 double frexp(double <[val]>, int *<[exp]>);
15 float frexpf(float <[val]>, int *<[exp]>);
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
26 <[m]> and <[p]> are calculated so that
27 <[val]> is <[m]> times <<2>> to the power <[p]>.
30 <[m]> and <[p]> are calculated so that
31 $ val = m \times 2^p $.
34 <<frexpf>> is identical, other than taking and returning
35 floats rather than doubles.
38 <<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
39 or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
43 <<frexpf>> is an extension.
48 /*****************************************************************
52 * d - floating point value
53 * exp - exponent value
56 * A floating point value in the range [0.5, 1).
59 * This routine breaks a floating point value into a number f and
60 * an exponent exp such that d = f * 2 ^ exp.
62 *****************************************************************/
67 #ifndef _DOUBLE_IS_32BITS
69 double frexp (double d
, int *exp
)
72 __uint32_t hd
, ld
, hf
, lf
;
74 /* Check for special values. */
85 EXTRACT_WORDS (hd
, ld
, d
);
87 /* Get the exponent. */
88 *exp
= ((hd
& 0x7ff00000) >> 20) - 1022;
90 /* Get the mantissa. */
95 INSERT_WORDS (f
, hf
, lf
);
100 #endif /* _DOUBLE_IS_32BITS */