error: Avoid "function declaration isn't a prototype" warning.
[gnulib.git] / tests / test-frexp.h
blob40524eddbb5fb828480b3082aaa64bee00dbbe16
1 /* Test of splitting a double into fraction and mantissa.
2 Copyright (C) 2012-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 static DOUBLE
18 my_ldexp (DOUBLE x, int d)
20 for (; d > 0; d--)
21 x *= L_(2.0);
22 for (; d < 0; d++)
23 x *= L_(0.5);
24 return x;
27 static void
28 test_function (void)
30 int i;
31 VOLATILE DOUBLE x;
33 { /* NaN. */
34 int exp = -9999;
35 DOUBLE mantissa;
36 x = NAN;
37 mantissa = FREXP (x, &exp);
38 ASSERT (ISNAN (mantissa));
41 { /* Positive infinity. */
42 int exp = -9999;
43 DOUBLE mantissa;
44 x = INFINITY;
45 mantissa = FREXP (x, &exp);
46 ASSERT (mantissa == x);
49 { /* Negative infinity. */
50 int exp = -9999;
51 DOUBLE mantissa;
52 x = - INFINITY;
53 mantissa = FREXP (x, &exp);
54 ASSERT (mantissa == x);
57 { /* Positive zero. */
58 int exp = -9999;
59 DOUBLE mantissa;
60 x = L_(0.0);
61 mantissa = FREXP (x, &exp);
62 ASSERT (exp == 0);
63 ASSERT (mantissa == x);
64 ASSERT (!signbit (mantissa));
67 { /* Negative zero. */
68 int exp = -9999;
69 DOUBLE mantissa;
70 x = MINUS_ZERO;
71 mantissa = FREXP (x, &exp);
72 ASSERT (exp == 0);
73 ASSERT (mantissa == x);
74 ASSERT (signbit (mantissa));
77 for (i = 1, x = L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
79 int exp = -9999;
80 DOUBLE mantissa = FREXP (x, &exp);
81 ASSERT (exp == i);
82 ASSERT (mantissa == L_(0.5));
84 for (i = 1, x = L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
86 int exp = -9999;
87 DOUBLE mantissa = FREXP (x, &exp);
88 ASSERT (exp == i);
89 ASSERT (mantissa == L_(0.5));
91 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
93 int exp = -9999;
94 DOUBLE mantissa = FREXP (x, &exp);
95 ASSERT (exp == i);
96 ASSERT (mantissa == L_(0.5));
99 for (i = 1, x = - L_(1.0); i <= MAX_EXP; i++, x *= L_(2.0))
101 int exp = -9999;
102 DOUBLE mantissa = FREXP (x, &exp);
103 ASSERT (exp == i);
104 ASSERT (mantissa == - L_(0.5));
106 for (i = 1, x = - L_(1.0); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
108 int exp = -9999;
109 DOUBLE mantissa = FREXP (x, &exp);
110 ASSERT (exp == i);
111 ASSERT (mantissa == - L_(0.5));
113 for (; i >= MIN_EXP - 100 && x < L_(0.0); i--, x *= L_(0.5))
115 int exp = -9999;
116 DOUBLE mantissa = FREXP (x, &exp);
117 ASSERT (exp == i);
118 ASSERT (mantissa == - L_(0.5));
121 for (i = 1, x = L_(1.01); i <= MAX_EXP; i++, x *= L_(2.0))
123 int exp = -9999;
124 DOUBLE mantissa = FREXP (x, &exp);
125 ASSERT (exp == i);
126 ASSERT (mantissa == L_(0.505));
128 for (i = 1, x = L_(1.01); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
130 int exp = -9999;
131 DOUBLE mantissa = FREXP (x, &exp);
132 ASSERT (exp == i);
133 ASSERT (mantissa == L_(0.505));
135 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
137 int exp = -9999;
138 DOUBLE mantissa = FREXP (x, &exp);
139 ASSERT (exp == i);
140 ASSERT (mantissa >= L_(0.5));
141 ASSERT (mantissa < L_(1.0));
142 ASSERT (mantissa == my_ldexp (x, - exp));
145 for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0))
147 int exp = -9999;
148 DOUBLE mantissa = FREXP (x, &exp);
149 ASSERT (exp == i);
150 ASSERT (mantissa == L_(0.866025));
152 for (i = 1, x = L_(1.73205); i >= MIN_NORMAL_EXP; i--, x *= L_(0.5))
154 int exp = -9999;
155 DOUBLE mantissa = FREXP (x, &exp);
156 ASSERT (exp == i);
157 ASSERT (mantissa == L_(0.866025));
159 for (; i >= MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
161 int exp = -9999;
162 DOUBLE mantissa = FREXP (x, &exp);
163 ASSERT (exp == i || exp == i + 1);
164 ASSERT (mantissa >= L_(0.5));
165 ASSERT (mantissa < L_(1.0));
166 ASSERT (mantissa == my_ldexp (x, - exp));
169 /* Randomized tests. */
170 for (i = 0; i < SIZEOF (RANDOM); i++)
172 x = L_(20.0) * RANDOM[i] - L_(10.0); /* -10.0 <= x <= 10.0 */
174 int exp = -9999;
175 DOUBLE mantissa = FREXP (x, &exp);
176 ASSERT (x == my_ldexp (mantissa, exp));