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