Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | |
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 | FUNCTION |
||
15 | < |
||
16 | INDEX |
||
17 | frexp |
||
18 | INDEX |
||
19 | frexpf |
||
20 | |||
21 | |||
22 | #include |
||
23 | double frexp(double <[val]>, int *<[exp]>); |
||
24 | float frexpf(float <[val]>, int *<[exp]>); |
||
25 | |||
26 | |||
27 | #include |
||
28 | double frexp(<[val]>, <[exp]>) |
||
29 | double <[val]>; |
||
30 | int *<[exp]>; |
||
31 | |||
32 | |||
33 | float <[val]>; |
||
34 | int *<[exp]>; |
||
35 | |||
36 | |||
37 | |||
38 | All nonzero, normal numbers can be described as <[m]> * 2**<[p]>. |
||
39 | < |
||
40 | and a power of two <[p]>. The resulting mantissa will always |
||
41 | be greater than or equal to <<0.5>>, and less than <<1.0>> (as |
||
42 | long as <[val]> is nonzero). The power of two will be stored |
||
43 | in <<*>><[exp]>. |
||
44 | |||
45 | |||
46 | <[m]> and <[p]> are calculated so that |
||
47 | <[val]> is <[m]> times <<2>> to the power <[p]>. |
||
48 | @end ifnottex |
||
49 | @tex |
||
50 | <[m]> and <[p]> are calculated so that |
||
51 | $ val = m \times 2^p $. |
||
52 | @end tex |
||
53 | |||
54 | |||
55 | floats rather than doubles. |
||
56 | |||
57 | |||
58 | < |
||
59 | or Nan, < |
||
60 | |||
61 | |||
62 | < |
||
63 | < |
||
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
69 | * for non-zero x |
||
70 | * x = frexp(arg,&exp); |
||
71 | * return a double fp quantity x such that 0.5 <= |x| <1.0 |
||
72 | * and the corresponding binary exponent "exp". That is |
||
73 | * arg = x*2^exp. |
||
74 | * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg |
||
75 | * with *exp=0. |
||
76 | */ |
||
77 | |||
78 | |||
79 | |||
80 | |||
81 | |||
82 | |||
83 | static const double |
||
84 | #else |
||
85 | static double |
||
86 | #endif |
||
87 | two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ |
||
88 | |||
89 | |||
90 | double frexp(double x, int *eptr) |
||
91 | #else |
||
92 | double frexp(x, eptr) |
||
93 | double x; int *eptr; |
||
94 | #endif |
||
95 | { |
||
96 | __int32_t hx, ix, lx; |
||
97 | EXTRACT_WORDS(hx,lx,x); |
||
98 | ix = 0x7fffffff&hx; |
||
99 | *eptr = 0; |
||
100 | if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ |
||
101 | if (ix<0x00100000) { /* subnormal */ |
||
102 | x *= two54; |
||
103 | GET_HIGH_WORD(hx,x); |
||
104 | ix = hx&0x7fffffff; |
||
105 | *eptr = -54; |
||
106 | } |
||
107 | *eptr += (ix>>20)-1022; |
||
108 | hx = (hx&0x800fffff)|0x3fe00000; |
||
109 | SET_HIGH_WORD(x,hx); |
||
110 | return x; |
||
111 | } |
||
112 | |||
113 | |||
114 | >=> |