2 /* @(#)s_frexp.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 <<frexp>>, <<frexpf>>---split floating-point number
24 double frexp(double <[val]>, int *<[exp]>);
25 float frexpf(float <[val]>, int *<[exp]>);
29 double frexp(<[val]>, <[exp]>)
33 float frexpf(<[val]>, <[exp]>)
39 All non zero, normal numbers can be described as <[m]> * 2**<[p]>.
40 <<frexp>> represents the double <[val]> as a mantissa <[m]>
41 and a power of two <[p]>. The resulting mantissa will always
42 be greater than or equal to <<0.5>>, and less than <<1.0>> (as
43 long as <[val]> is nonzero). The power of two will be stored
47 <[m]> and <[p]> are calculated so that
48 <[val]> is <[m]> times <<2>> to the power <[p]>.
51 <[m]> and <[p]> are calculated so that
52 $ val = m \times 2^p $.
55 <<frexpf>> is identical, other than taking and returning
56 floats rather than doubles.
59 <<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
60 or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
64 <<frexpf>> is an extension.
71 * x = frexp(arg,&exp);
72 * return a double fp quantity x such that 0.5 <= |x| <1.0
73 * and the corresponding binary exponent "exp". That is
75 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
81 #ifndef _DOUBLE_IS_32BITS
88 two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
91 double frexp(double x, int *eptr)
98 EXTRACT_WORDS(hx,lx,x);
101 if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
102 if (ix<0x00100000) { /* subnormal */
108 *eptr += (ix>>20)-1022;
109 hx = (hx&0x800fffff)|0x3fe00000;
114 #endif /* _DOUBLE_IS_32BITS */