Branch data Line data Source code
1 : : /* @(#)s_frexp.c 5.1 93/09/24 */
2 : : /*
3 : : * ====================================================
4 : : * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 : : *
6 : : * Developed at SunPro, a Sun Microsystems, Inc. business.
7 : : * Permission to use, copy, modify, and distribute this
8 : : * software is freely granted, provided that this notice
9 : : * is preserved.
10 : : * ====================================================
11 : : */
12 : :
13 : : #include "cdefs-compat.h"
14 : : //__FBSDID("$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.11 2008/02/22 02:30:35 das Exp $");
15 : :
16 : : /*
17 : : * for non-zero x
18 : : * x = frexp(arg,&exp);
19 : : * return a double fp quantity x such that 0.5 <= |x| <1.0
20 : : * and the corresponding binary exponent "exp". That is
21 : : * arg = x*2^exp.
22 : : * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
23 : : * with *exp=0.
24 : : */
25 : :
26 : : #include <float.h>
27 : : #include <openlibm_math.h>
28 : :
29 : : #include "math_private.h"
30 : :
31 : : static const double
32 : : two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
33 : :
34 : : OLM_DLLEXPORT double
35 : 10 : frexp(double x, int *eptr)
36 : : {
37 : : int32_t hx, ix, lx;
38 : 10 : EXTRACT_WORDS(hx,lx,x);
39 : 10 : ix = 0x7fffffff&hx;
40 : 10 : *eptr = 0;
41 [ + + + + ]: 10 : if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
42 [ - + ]: 5 : if (ix<0x00100000) { /* subnormal */
43 : 0 : x *= two54;
44 : 0 : GET_HIGH_WORD(hx,x);
45 : 0 : ix = hx&0x7fffffff;
46 : 0 : *eptr = -54;
47 : : }
48 : 5 : *eptr += (ix>>20)-1022;
49 : 5 : hx = (hx&0x800fffff)|0x3fe00000;
50 : 5 : SET_HIGH_WORD(x,hx);
51 : 5 : return x;
52 : : }
53 : :
54 : : #if (LDBL_MANT_DIG == 53)
55 : : openlibm_weak_reference(frexp, frexpl);
56 : : #endif
|