This source file includes following definitions.
- my_ldexp
- test_function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static DOUBLE
18 my_ldexp (DOUBLE x, int d)
19 {
20 for (; d > 0; d--)
21 x *= L_(2.0);
22 for (; d < 0; d++)
23 x *= L_(0.5);
24 return x;
25 }
26
27 static void
28 test_function (void)
29 {
30 int i;
31 VOLATILE DOUBLE x;
32 int y;
33
34
35 x = L_(0.6);
36 y = ILOGB (x);
37 ASSERT (y == -1);
38
39 x = L_(1.2);
40 y = ILOGB (x);
41 ASSERT (y == 0);
42
43 x = L_(2.1);
44 y = ILOGB (x);
45 ASSERT (y == 1);
46
47 x = L_(3.9);
48 y = ILOGB (x);
49 ASSERT (y == 1);
50
51 x = L_(4.0);
52 y = ILOGB (x);
53 ASSERT (y == (FLT_RADIX == 2 ? 2 : 1));
54
55 x = L_(0.25);
56 y = ILOGB (x);
57 ASSERT (y == (FLT_RADIX == 2 ? -2 : -1));
58
59
60 ASSERT (ILOGB (L_(0.0)) == FP_ILOGB0);
61 ASSERT (ILOGB (MINUS_ZERO) == FP_ILOGB0);
62
63
64 ASSERT (ILOGB (INFINITY) == INT_MAX);
65 ASSERT (ILOGB (- INFINITY) == INT_MAX);
66
67
68 ASSERT (ILOGB (NAN) == FP_ILOGBNAN);
69
70
71
72 for (i = 1, x = L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
73 {
74 y = ILOGB (x);
75 ASSERT (y == i - 1);
76 }
77 for (i = 1, x = L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
78 {
79 y = ILOGB (x);
80 ASSERT (y == i - 1);
81 }
82 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
83 {
84 y = ILOGB (x);
85 ASSERT (y == i - 1);
86 }
87
88 for (i = 1, x = - L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
89 {
90 y = ILOGB (x);
91 ASSERT (y == i - 1);
92 }
93 for (i = 1, x = - L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
94 {
95 y = ILOGB (x);
96 ASSERT (y == i - 1);
97 }
98 for (; i >= MIN_EXP - 100 && x < L_(0.0); i--, x *= L_(0.5))
99 {
100 y = ILOGB (x);
101 ASSERT (y == i - 1);
102 }
103
104 for (i = 1, x = L_(1.01); i <= MAX_EXP; i++, x *= L_(2.0))
105 {
106 y = ILOGB (x);
107 ASSERT (y == i - 1);
108 }
109 for (i = 1, x = L_(1.01); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
110 {
111 y = ILOGB (x);
112 ASSERT (y == i - 1);
113 }
114 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
115 {
116 y = ILOGB (x);
117 ASSERT (y == i - 1);
118 }
119
120 for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0))
121 {
122 y = ILOGB (x);
123 ASSERT (y == i - 1);
124 }
125 for (i = 1, x = L_(1.73205); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
126 {
127 y = ILOGB (x);
128 ASSERT (y == i - 1);
129 }
130 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
131 {
132 y = ILOGB (x);
133 ASSERT (y == i - 1 || y == i);
134 }
135
136
137 for (i = 0; i < SIZEOF (RANDOM); i++)
138 {
139 x = L_(20.0) * RANDOM[i] - L_(10.0);
140 if (x != L_(0.0))
141 {
142 DOUBLE abs_x = (x < L_(0.0) ? - x : x);
143 y = ILOGB (x);
144 ASSERT (abs_x >= my_ldexp (L_(1.0), y));
145 ASSERT (abs_x < my_ldexp (L_(1.0), y + 1));
146 }
147 }
148 }
149
150 volatile DOUBLE x;
151 DOUBLE y;