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 DOUBLE y;
33
34
35 x = L_(0.6);
36 y = LOGB (x);
37 ASSERT (y == - L_(1.0));
38
39 x = L_(1.2);
40 y = LOGB (x);
41 ASSERT (y == L_(0.0));
42
43 x = L_(2.1);
44 y = LOGB (x);
45 ASSERT (y == L_(1.0));
46
47 x = L_(3.9);
48 y = LOGB (x);
49 ASSERT (y == L_(1.0));
50
51 x = L_(4.0);
52 y = LOGB (x);
53 ASSERT (y == (FLT_RADIX == 2 ? L_(2.0) : L_(1.0)));
54
55 x = L_(0.25);
56 y = LOGB (x);
57 ASSERT (y == (FLT_RADIX == 2 ? - L_(2.0) : - L_(1.0)));
58
59
60 ASSERT (LOGB (L_(0.0)) == - HUGEVAL);
61 ASSERT (LOGB (MINUS_ZERO) == - HUGEVAL);
62
63
64
65 for (i = 1, x = L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
66 {
67 y = LOGB (x);
68 ASSERT (y == (DOUBLE)(i - 1));
69 }
70 for (i = 1, x = L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
71 {
72 y = LOGB (x);
73 ASSERT (y == (DOUBLE)(i - 1));
74 }
75 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
76 {
77 y = LOGB (x);
78 ASSERT (y == (DOUBLE)(i - 1));
79 }
80
81 for (i = 1, x = - L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
82 {
83 y = LOGB (x);
84 ASSERT (y == (DOUBLE)(i - 1));
85 }
86 for (i = 1, x = - L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
87 {
88 y = LOGB (x);
89 ASSERT (y == (DOUBLE)(i - 1));
90 }
91 for (; i >= MIN_EXP - 100 && x < L_(0.0); i--, x *= L_(0.5))
92 {
93 y = LOGB (x);
94 ASSERT (y == (DOUBLE)(i - 1));
95 }
96
97 for (i = 1, x = L_(1.01); i <= MAX_EXP; i++, x *= L_(2.0))
98 {
99 y = LOGB (x);
100 ASSERT (y == (DOUBLE)(i - 1));
101 }
102 for (i = 1, x = L_(1.01); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
103 {
104 y = LOGB (x);
105 ASSERT (y == (DOUBLE)(i - 1));
106 }
107 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
108 {
109 y = LOGB (x);
110 ASSERT (y == (DOUBLE)(i - 1));
111 }
112
113 for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0))
114 {
115 y = LOGB (x);
116 ASSERT (y == (DOUBLE)(i - 1));
117 }
118 for (i = 1, x = L_(1.73205); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
119 {
120 y = LOGB (x);
121 ASSERT (y == (DOUBLE)(i - 1));
122 }
123 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
124 {
125 y = LOGB (x);
126 ASSERT (y == (DOUBLE)(i - 1) || y == (DOUBLE)i);
127 }
128
129
130 for (i = 0; i < SIZEOF (RANDOM); i++)
131 {
132 x = L_(20.0) * RANDOM[i] - L_(10.0);
133 if (x != L_(0.0))
134 {
135 DOUBLE abs_x = (x < L_(0.0) ? - x : x);
136 y = LOGB (x);
137 ASSERT (y == (DOUBLE) (int) y);
138 ASSERT (abs_x >= my_ldexp (L_(1.0), (int) y));
139 ASSERT (abs_x < my_ldexp (L_(1.0), (int) y + 1));
140 }
141 }
142 }
143
144 volatile DOUBLE x;
145 DOUBLE y;