1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
5  * Developed at SunPro, a Sun Microsystems, Inc. business.
6  * Permission to use, copy, modify, and distribute this
7  * software is freely granted, provided that this notice
8  * is preserved.
9  * ====================================================
10  */
11 
12 /*
13  * for non-zero x
14  *	x = frexp(arg,&exp);
15  * return a double fp quantity x such that 0.5 <= |x| <1.0
16  * and the corresponding binary exponent "exp". That is
17  *	arg = x*2^exp.
18  * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
19  * with *exp=0.
20  */
21 
22 #include "math.h"
23 #include "math_private.h"
24 
25 static const double
26 two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
27 
frexp(double x,int * eptr)28 double frexp(double x, int *eptr)
29 {
30 	int32_t hx, ix, lx;
31 	EXTRACT_WORDS(hx,lx,x);
32 	ix = 0x7fffffff&hx;
33 	*eptr = 0;
34 	if(ix>=0x7ff00000||((ix|lx)==0)) return x;	/* 0,inf,nan */
35 	if (ix<0x00100000) {		/* subnormal */
36 	    x *= two54;
37 	    GET_HIGH_WORD(hx,x);
38 	    ix = hx&0x7fffffff;
39 	    *eptr = -54;
40 	}
41 	*eptr += (ix>>20)-1022;
42 	hx = (hx&0x800fffff)|0x3fe00000;
43 	SET_HIGH_WORD(x,hx);
44 	return x;
45 }
46 libm_hidden_def(frexp)
47