13a8617a8SJordan K. Hubbard /*
23a8617a8SJordan K. Hubbard * ====================================================
33a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
43a8617a8SJordan K. Hubbard *
53a8617a8SJordan K. Hubbard * Developed at SunPro, a Sun Microsystems, Inc. business.
63a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this
73a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice
83a8617a8SJordan K. Hubbard * is preserved.
93a8617a8SJordan K. Hubbard * ====================================================
103a8617a8SJordan K. Hubbard */
113a8617a8SJordan K. Hubbard
123a8617a8SJordan K. Hubbard /*
133a8617a8SJordan K. Hubbard * for non-zero x
143a8617a8SJordan K. Hubbard * x = frexp(arg,&exp);
153a8617a8SJordan K. Hubbard * return a double fp quantity x such that 0.5 <= |x| <1.0
163a8617a8SJordan K. Hubbard * and the corresponding binary exponent "exp". That is
173a8617a8SJordan K. Hubbard * arg = x*2^exp.
183a8617a8SJordan K. Hubbard * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
193a8617a8SJordan K. Hubbard * with *exp=0.
203a8617a8SJordan K. Hubbard */
213a8617a8SJordan K. Hubbard
22f8a40fcaSDavid Schultz #include <float.h>
23f8a40fcaSDavid Schultz
243a8617a8SJordan K. Hubbard #include "math.h"
253a8617a8SJordan K. Hubbard #include "math_private.h"
263a8617a8SJordan K. Hubbard
273a8617a8SJordan K. Hubbard static const double
283a8617a8SJordan K. Hubbard two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
293a8617a8SJordan K. Hubbard
3059b19ff1SAlfred Perlstein double
frexp(double x,int * eptr)3159b19ff1SAlfred Perlstein frexp(double x, int *eptr)
323a8617a8SJordan K. Hubbard {
333a8617a8SJordan K. Hubbard int32_t hx, ix, lx;
343a8617a8SJordan K. Hubbard EXTRACT_WORDS(hx,lx,x);
353a8617a8SJordan K. Hubbard ix = 0x7fffffff&hx;
363a8617a8SJordan K. Hubbard *eptr = 0;
373a8617a8SJordan K. Hubbard if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
383a8617a8SJordan K. Hubbard if (ix<0x00100000) { /* subnormal */
393a8617a8SJordan K. Hubbard x *= two54;
403a8617a8SJordan K. Hubbard GET_HIGH_WORD(hx,x);
413a8617a8SJordan K. Hubbard ix = hx&0x7fffffff;
423a8617a8SJordan K. Hubbard *eptr = -54;
433a8617a8SJordan K. Hubbard }
443a8617a8SJordan K. Hubbard *eptr += (ix>>20)-1022;
453a8617a8SJordan K. Hubbard hx = (hx&0x800fffff)|0x3fe00000;
463a8617a8SJordan K. Hubbard SET_HIGH_WORD(x,hx);
473a8617a8SJordan K. Hubbard return x;
483a8617a8SJordan K. Hubbard }
49f8a40fcaSDavid Schultz
50f8a40fcaSDavid Schultz #if (LDBL_MANT_DIG == 53)
513d266bdeSDavid Schultz __weak_reference(frexp, frexpl);
52f8a40fcaSDavid Schultz #endif
53