Numworks Epsilon  1.4.1
Graphing Calculator Operating System
s_frexp.c
Go to the documentation of this file.
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 /*
14  * for non-zero x
15  * x = frexp(arg,&exp);
16  * return a double fp quantity x such that 0.5 <= |x| <1.0
17  * and the corresponding binary exponent "exp". That is
18  * arg = x*2^exp.
19  * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
20  * with *exp=0.
21  */
22 
23 #include <sys/cdefs.h>
24 #include <float.h>
25 #include <math.h>
26 
27 #include "math_private.h"
28 
29 static const double
30 two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
31 
32 double
33 frexp(double x, int *eptr)
34 {
35  int32_t hx, ix, lx;
36  EXTRACT_WORDS(hx,lx,x);
37  ix = 0x7fffffff&hx;
38  *eptr = 0;
39  if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
40  if (ix<0x00100000) { /* subnormal */
41  x *= two54;
42  GET_HIGH_WORD(hx,x);
43  ix = hx&0x7fffffff;
44  *eptr = -54;
45  }
46  *eptr += (ix>>20)-1022;
47  hx = (hx&0x800fffff)|0x3fe00000;
48  SET_HIGH_WORD(x,hx);
49  return x;
50 }
51 
52 #if LDBL_MANT_DIG == 53
53 #ifdef __weak_alias
54 __weak_alias(frexpl, frexp);
55 #endif /* __weak_alias */
56 #endif /* LDBL_MANT_DIG == 53 */
#define GET_HIGH_WORD(i, d)
Definition: math_private.h:269
double frexp(double x, int *eptr)
Definition: s_frexp.c:33
#define SET_HIGH_WORD(d, v)
Definition: math_private.h:297
#define EXTRACT_WORDS(ix0, ix1, d)
Definition: math_private.h:259
signed int int32_t
Definition: stdint.h:11