arc: Merge ARCv2 string routines in generic ARC .S files
[uclibc-ng.git] / libm / s_frexp.c
blob212ec47afae2daf4c95930fddb992407417e62c3
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
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.
22 #include "math.h"
23 #include "math_private.h"
25 static const double
26 two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
28 double frexp(double x, int *eptr)
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;
41 *eptr += (ix>>20)-1022;
42 hx = (hx&0x800fffff)|0x3fe00000;
43 SET_HIGH_WORD(x,hx);
44 return x;
46 libm_hidden_def(frexp)