source: mainline/uspace/lib/math/test/rounding.c@ dc68f72

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dc68f72 was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 32.6 KB
Line 
1/*
2 * Copyright (c) 2018 CZ.NIC, z.s.p.o.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <pcut/pcut.h>
30#include <math.h>
31#include <inttypes.h>
32
33PCUT_INIT;
34
35PCUT_TEST_SUITE(rounding);
36
37static inline uint32_t fint(float x)
38{
39 union {
40 float f;
41 uint32_t i;
42 } u = { .f = x };
43 return u.i;
44}
45
46static inline uint64_t dint(double x)
47{
48 union {
49 double f;
50 uint64_t i;
51 } u = { .f = x };
52 return u.i;
53}
54
55#define assert_float_equals(x, y) PCUT_ASSERT_EQUALS(fint(x), fint(y))
56#define assert_double_equals(x, y) PCUT_ASSERT_EQUALS(dint(x), dint(y))
57
58#define FLOAT_CASES 200
59#define DOUBLE_CASES 0
60
61static float float_arguments[FLOAT_CASES] = {
62 HUGE_VALF,
63 -HUGE_VALF,
64 __builtin_nanf(""),
65 -__builtin_nanf(""),
66 __builtin_nanf("0xdeadbe"),
67 -__builtin_nanf("0xdeadbe"),
68
69 0x0.000000p0f, /* zero */
70 0x0.000002p-126f, /* smallest denormal > 0 */
71 0x1.000000p-126f, /* smallest normal > 0 */
72 0x1.fffffep-2f, /* largest < 0.5 */
73 0x1.000000p-1f, /* 0.5 */
74 0x1.000002p-1f, /* smallest > 0.5 */
75 0x1.fffffep-1f, /* largest < 1 */
76 0x1.000000p0f, /* 1 */
77 0x1.000002p0f, /* smallest > 1 */
78 0x1.7ffffep0f, /* largest < 1.5 */
79 0x1.800000p0f, /* 1.5 */
80 0x1.800002p0f, /* smallest > 1.5 */
81 0x1.fffffep0f, /* largest < 2 */
82 0x1.000000p1f, /* 2 */
83 0x1.000002p1f, /* smallest > 2 */
84 0x1.3ffffep1f, /* largest < 2.5 */
85 0x1.400000p1f, /* 2.5 */
86 0x1.400002p1f, /* smallest > 2.5 */
87 0x1.7ffffep1f, /* largest < 3 */
88 0x1.800000p1f, /* 3 */
89 0x1.800002p1f, /* smallest > 3 */
90 0x1.bffffep1f, /* largest < 3.5 */
91 0x1.c00000p1f, /* 3.5 */
92 0x1.c00002p1f, /* smallest > 3.5 */
93 0x1.fffffep1f, /* largest < 4 */
94 0x1.000000p2f, /* 4 */
95 0x1.000002p2f, /* smallest > 4 */
96
97 0x1.ffffe0p20f, /* 2^21 - 2 */
98 0x1.ffffe2p20f, /* 2^21 - 1.875 */
99 0x1.ffffe4p20f, /* 2^21 - 1.75 */
100 0x1.ffffe6p20f, /* 2^21 - 1.625 */
101 0x1.ffffe8p20f, /* 2^21 - 1.5 */
102 0x1.ffffeap20f, /* 2^21 - 1.375 */
103 0x1.ffffecp20f, /* 2^21 - 1.25 */
104 0x1.ffffeep20f, /* 2^21 - 1.125 */
105 0x1.fffff0p20f, /* 2^21 - 1 */
106 0x1.fffff2p20f, /* 2^21 - 0.875 */
107 0x1.fffff4p20f, /* 2^21 - 0.75 */
108 0x1.fffff6p20f, /* 2^21 - 0.625 */
109 0x1.fffff8p20f, /* 2^21 - 0.5 */
110 0x1.fffffap20f, /* 2^21 - 0.375 */
111 0x1.fffffcp20f, /* 2^21 - 0.25 */
112 0x1.fffffep20f, /* 2^21 - 0.125 */
113 0x1.000000p21f, /* 2^21 */
114 0x1.000002p21f, /* 2^21 + 0.25 */
115 0x1.000004p21f, /* 2^21 + 0.5 */
116 0x1.000006p21f, /* 2^21 + 0.75 */
117 0x1.000008p21f, /* 2^21 + 1 */
118 0x1.00000ap21f, /* 2^21 + 1.25 */
119 0x1.00000cp21f, /* 2^21 + 1.5 */
120 0x1.00000ep21f, /* 2^21 + 1.75 */
121 0x1.000010p21f, /* 2^21 + 2 */
122
123 0x1.fffff0p21f, /* 2^22 - 2 */
124 0x1.fffff2p21f, /* 2^22 - 1.75 */
125 0x1.fffff4p21f, /* 2^22 - 1.5 */
126 0x1.fffff6p21f, /* 2^22 - 1.25 */
127 0x1.fffff8p21f, /* 2^22 - 1 */
128 0x1.fffffap21f, /* 2^22 - 0.75 */
129 0x1.fffffcp21f, /* 2^22 - 0.5 */
130 0x1.fffffep21f, /* 2^22 - 0.25 */
131 0x1.000000p22f, /* 2^22 */
132 0x1.000002p22f, /* 2^22 + 0.5 */
133 0x1.000004p22f, /* 2^22 + 1 */
134 0x1.000006p22f, /* 2^22 + 1.5 */
135 0x1.000008p22f, /* 2^22 + 2 */
136
137 0x1.fffff0p22f, /* 2^23 - 4 */
138 0x1.fffff2p22f, /* 2^23 - 3.5 */
139 0x1.fffff4p22f, /* 2^23 - 3 */
140 0x1.fffff6p22f, /* 2^23 - 2.5 */
141 0x1.fffff8p22f, /* 2^23 - 2 */
142 0x1.fffffap22f, /* 2^23 - 1.5 */
143 0x1.fffffcp22f, /* 2^23 - 1 */
144 0x1.fffffep22f, /* 2^23 - 0.5 */
145 0x1.000000p23f, /* 2^23 */
146 0x1.000002p23f, /* 2^23 + 1 */
147 0x1.000004p23f, /* 2^23 + 2 */
148 0x1.000006p23f, /* 2^23 + 3 */
149 0x1.000008p23f, /* 2^23 + 4 */
150
151 0x1.fffff0p23f, /* 2^24 - 8 */
152 0x1.fffff2p23f, /* 2^24 - 7 */
153 0x1.fffff4p23f, /* 2^24 - 6 */
154 0x1.fffff6p23f, /* 2^24 - 5 */
155 0x1.fffff8p23f, /* 2^24 - 4 */
156 0x1.fffffap23f, /* 2^24 - 3 */
157 0x1.fffffcp23f, /* 2^24 - 2 */
158 0x1.fffffep23f, /* 2^24 - 1 */
159 0x1.000000p24f, /* 2^24 */
160 0x1.000002p24f, /* 2^24 + 2 */
161 0x1.000004p24f, /* 2^24 + 4 */
162 0x1.000006p24f, /* 2^24 + 6 */
163 0x1.000008p24f, /* 2^24 + 8 */
164
165 0x1.fffffep100f, /* large integer */
166
167 /* Same as above but negative */
168
169 -0x0.000000p0f, /* zero */
170 -0x0.000002p-126f, /* smallest denormal > 0 */
171 -0x1.000000p-126f, /* smallest normal > 0 */
172 -0x1.fffffep-2f, /* largest < 0.5 */
173 -0x1.000000p-1f, /* 0.5 */
174 -0x1.000002p-1f, /* smallest > 0.5 */
175 -0x1.fffffep-1f, /* largest < 1 */
176 -0x1.000000p0f, /* 1 */
177 -0x1.000002p0f, /* smallest > 1 */
178 -0x1.7ffffep0f, /* largest < 1.5 */
179 -0x1.800000p0f, /* 1.5 */
180 -0x1.800002p0f, /* smallest > 1.5 */
181 -0x1.fffffep0f, /* largest < 2 */
182 -0x1.000000p1f, /* 2 */
183 -0x1.000002p1f, /* smallest > 2 */
184 -0x1.3ffffep1f, /* largest < 2.5 */
185 -0x1.400000p1f, /* 2.5 */
186 -0x1.400002p1f, /* smallest > 2.5 */
187 -0x1.7ffffep1f, /* largest < 3 */
188 -0x1.800000p1f, /* 3 */
189 -0x1.800002p1f, /* smallest > 3 */
190 -0x1.bffffep1f, /* largest < 3.5 */
191 -0x1.c00000p1f, /* 3.5 */
192 -0x1.c00002p1f, /* smallest > 3.5 */
193 -0x1.fffffep1f, /* largest < 4 */
194 -0x1.000000p2f, /* 4 */
195 -0x1.000002p2f, /* smallest > 4 */
196
197 -0x1.ffffe0p20f, /* 2^21 - 2 */
198 -0x1.ffffe2p20f, /* 2^21 - 1.875 */
199 -0x1.ffffe4p20f, /* 2^21 - 1.75 */
200 -0x1.ffffe6p20f, /* 2^21 - 1.625 */
201 -0x1.ffffe8p20f, /* 2^21 - 1.5 */
202 -0x1.ffffeap20f, /* 2^21 - 1.375 */
203 -0x1.ffffecp20f, /* 2^21 - 1.25 */
204 -0x1.ffffeep20f, /* 2^21 - 1.125 */
205 -0x1.fffff0p20f, /* 2^21 - 1 */
206 -0x1.fffff2p20f, /* 2^21 - 0.875 */
207 -0x1.fffff4p20f, /* 2^21 - 0.75 */
208 -0x1.fffff6p20f, /* 2^21 - 0.625 */
209 -0x1.fffff8p20f, /* 2^21 - 0.5 */
210 -0x1.fffffap20f, /* 2^21 - 0.375 */
211 -0x1.fffffcp20f, /* 2^21 - 0.25 */
212 -0x1.fffffep20f, /* 2^21 - 0.125 */
213 -0x1.000000p21f, /* 2^21 */
214 -0x1.000002p21f, /* 2^21 + 0.25 */
215 -0x1.000004p21f, /* 2^21 + 0.5 */
216 -0x1.000006p21f, /* 2^21 + 0.75 */
217 -0x1.000008p21f, /* 2^21 + 1 */
218 -0x1.00000ap21f, /* 2^21 + 1.25 */
219 -0x1.00000cp21f, /* 2^21 + 1.5 */
220 -0x1.00000ep21f, /* 2^21 + 1.75 */
221 -0x1.000010p21f, /* 2^21 + 2 */
222
223 -0x1.fffff0p21f, /* 2^22 - 2 */
224 -0x1.fffff2p21f, /* 2^22 - 1.75 */
225 -0x1.fffff4p21f, /* 2^22 - 1.5 */
226 -0x1.fffff6p21f, /* 2^22 - 1.25 */
227 -0x1.fffff8p21f, /* 2^22 - 1 */
228 -0x1.fffffap21f, /* 2^22 - 0.75 */
229 -0x1.fffffcp21f, /* 2^22 - 0.5 */
230 -0x1.fffffep21f, /* 2^22 - 0.25 */
231 -0x1.000000p22f, /* 2^22 */
232 -0x1.000002p22f, /* 2^22 + 0.5 */
233 -0x1.000004p22f, /* 2^22 + 1 */
234 -0x1.000006p22f, /* 2^22 + 1.5 */
235 -0x1.000008p22f, /* 2^22 + 2 */
236
237 -0x1.fffff0p22f, /* 2^23 - 4 */
238 -0x1.fffff2p22f, /* 2^23 - 3.5 */
239 -0x1.fffff4p22f, /* 2^23 - 3 */
240 -0x1.fffff6p22f, /* 2^23 - 2.5 */
241 -0x1.fffff8p22f, /* 2^23 - 2 */
242 -0x1.fffffap22f, /* 2^23 - 1.5 */
243 -0x1.fffffcp22f, /* 2^23 - 1 */
244 -0x1.fffffep22f, /* 2^23 - 0.5 */
245 -0x1.000000p23f, /* 2^23 */
246 -0x1.000002p23f, /* 2^23 + 1 */
247 -0x1.000004p23f, /* 2^23 + 2 */
248 -0x1.000006p23f, /* 2^23 + 3 */
249 -0x1.000008p23f, /* 2^23 + 4 */
250
251 -0x1.fffff0p23f, /* 2^24 - 8 */
252 -0x1.fffff2p23f, /* 2^24 - 7 */
253 -0x1.fffff4p23f, /* 2^24 - 6 */
254 -0x1.fffff6p23f, /* 2^24 - 5 */
255 -0x1.fffff8p23f, /* 2^24 - 4 */
256 -0x1.fffffap23f, /* 2^24 - 3 */
257 -0x1.fffffcp23f, /* 2^24 - 2 */
258 -0x1.fffffep23f, /* 2^24 - 1 */
259 -0x1.000000p24f, /* 2^24 */
260 -0x1.000002p24f, /* 2^24 + 2 */
261 -0x1.000004p24f, /* 2^24 + 4 */
262 -0x1.000006p24f, /* 2^24 + 6 */
263 -0x1.000008p24f, /* 2^24 + 8 */
264
265 -0x1.fffffep100f, /* large integer with full mantissa */
266
267 /* a few random numbers*/
268 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0
269};
270
271static float float_identity[FLOAT_CASES] = {
272 HUGE_VALF,
273 -HUGE_VALF,
274 __builtin_nanf(""),
275 -__builtin_nanf(""),
276 __builtin_nanf("0xdeadbe"),
277 -__builtin_nanf("0xdeadbe"),
278
279 0.0,
280 FLT_DENORM_MIN, /* smallest denormal > 0 */
281 FLT_MIN, /* smallest normal > 0 */
282 0.5 - (FLT_EPSILON / 4.),
283 0.5,
284 0.5 + (FLT_EPSILON / 2.),
285 1.0 - (FLT_EPSILON / 2.),
286 1.0,
287 1.0 + FLT_EPSILON,
288 1.5 - FLT_EPSILON,
289 1.5,
290 1.5 + FLT_EPSILON,
291 2.0 - FLT_EPSILON,
292 2.0,
293 2.0 + (2.0 * FLT_EPSILON),
294 2.5 - (2.0 * FLT_EPSILON),
295 2.5,
296 2.5 + (2.0 * FLT_EPSILON),
297 3.0 - (2.0 * FLT_EPSILON),
298 3.0,
299 3.0 + (2.0 * FLT_EPSILON),
300 3.5 - (2.0 * FLT_EPSILON),
301 3.5,
302 3.5 + (2.0 * FLT_EPSILON),
303 4.0 - (2.0 * FLT_EPSILON),
304 4.0,
305 4.0 + (4.0 * FLT_EPSILON),
306
307 2097150.000, /* 2^21 - 2 */
308 2097150.125, /* 2^21 - 1.875 */
309 2097150.250, /* 2^21 - 1.75 */
310 2097150.375, /* 2^21 - 1.625 */
311 2097150.500, /* 2^21 - 1.5 */
312 2097150.625, /* 2^21 - 1.375 */
313 2097150.750, /* 2^21 - 1.25 */
314 2097150.875, /* 2^21 - 1.125 */
315 2097151.000, /* 2^21 - 1 */
316 2097151.125, /* 2^21 - 0.875 */
317 2097151.250, /* 2^21 - 0.75 */
318 2097151.375, /* 2^21 - 0.625 */
319 2097151.500, /* 2^21 - 0.5 */
320 2097151.625, /* 2^21 - 0.375 */
321 2097151.750, /* 2^21 - 0.25 */
322 2097151.875, /* 2^21 - 0.125 */
323 2097152.00, /* 2^21 */
324 2097152.25, /* 2^21 + 0.25 */
325 2097152.50, /* 2^21 + 0.5 */
326 2097152.75, /* 2^21 + 0.75 */
327 2097153.00, /* 2^21 + 1 */
328 2097153.25, /* 2^21 + 1.25 */
329 2097153.50, /* 2^21 + 1.5 */
330 2097153.75, /* 2^21 + 1.75 */
331 2097154.00, /* 2^21 + 2 */
332
333 4194302.00, /* 2^22 - 2 */
334 4194302.25, /* 2^22 - 1.75 */
335 4194302.50, /* 2^22 - 1.5 */
336 4194302.75, /* 2^22 - 1.25 */
337 4194303.00, /* 2^22 - 1 */
338 4194303.25, /* 2^22 - 0.75 */
339 4194303.50, /* 2^22 - 0.5 */
340 4194303.75, /* 2^22 - 0.25 */
341 4194304.0, /* 2^22 */
342 4194304.5, /* 2^22 + 0.5 */
343 4194305.0, /* 2^22 + 1 */
344 4194305.5, /* 2^22 + 1.5 */
345 4194306.0, /* 2^22 + 2 */
346
347 8388604.0, /* 2^23 - 4 */
348 8388604.5, /* 2^23 - 3.5 */
349 8388605.0, /* 2^23 - 3 */
350 8388605.5, /* 2^23 - 2.5 */
351 8388606.0, /* 2^23 - 2 */
352 8388606.5, /* 2^23 - 1.5 */
353 8388607.0, /* 2^23 - 1 */
354 8388607.5, /* 2^23 - 0.5 */
355 8388608.0, /* 2^23 */
356 8388609.0, /* 2^23 + 1 */
357 8388610.0, /* 2^23 + 2 */
358 8388611.0, /* 2^23 + 3 */
359 8388612.0, /* 2^23 + 4 */
360
361 16777208.0, /* 2^24 - 8 */
362 16777209.0, /* 2^24 - 7 */
363 16777210.0, /* 2^24 - 6 */
364 16777211.0, /* 2^24 - 5 */
365 16777212.0, /* 2^24 - 4 */
366 16777213.0, /* 2^24 - 3 */
367 16777214.0, /* 2^24 - 2 */
368 16777215.0, /* 2^24 - 1 */
369 16777216.0, /* 2^24 */
370 16777218.0, /* 2^24 + 2 */
371 16777220.0, /* 2^24 + 4 */
372 16777222.0, /* 2^24 + 6 */
373 16777224.0, /* 2^24 + 8 */
374
375 0x1.fffffep100f, /* large integer with full mantissa */
376
377 /* Same as above but negative */
378
379 -0.0,
380 -FLT_DENORM_MIN, /* smallest denormal > 0 */
381 -FLT_MIN, /* smallest normal > 0 */
382 -(0.5 - (FLT_EPSILON / 4.)),
383 -0.5,
384 -(0.5 + (FLT_EPSILON / 2.)),
385 -(1.0 - (FLT_EPSILON / 2.)),
386 -1.0,
387 -(1.0 + FLT_EPSILON),
388 -(1.5 - FLT_EPSILON),
389 -1.5,
390 -(1.5 + FLT_EPSILON),
391 -(2.0 - FLT_EPSILON),
392 -2.0,
393 -(2.0 + (2.0 * FLT_EPSILON)),
394 -(2.5 - (2.0 * FLT_EPSILON)),
395 -2.5,
396 -(2.5 + (2.0 * FLT_EPSILON)),
397 -(3.0 - (2.0 * FLT_EPSILON)),
398 -3.0,
399 -(3.0 + (2.0 * FLT_EPSILON)),
400 -(3.5 - (2.0 * FLT_EPSILON)),
401 -3.5,
402 -(3.5 + (2.0 * FLT_EPSILON)),
403 -(4.0 - (2.0 * FLT_EPSILON)),
404 -4.0,
405 -(4.0 + (4.0 * FLT_EPSILON)),
406
407 -2097150.000, /* 2^21 - 2 */
408 -2097150.125, /* 2^21 - 1.875 */
409 -2097150.250, /* 2^21 - 1.75 */
410 -2097150.375, /* 2^21 - 1.625 */
411 -2097150.500, /* 2^21 - 1.5 */
412 -2097150.625, /* 2^21 - 1.375 */
413 -2097150.750, /* 2^21 - 1.25 */
414 -2097150.875, /* 2^21 - 1.125 */
415 -2097151.000, /* 2^21 - 1 */
416 -2097151.125, /* 2^21 - 0.875 */
417 -2097151.250, /* 2^21 - 0.75 */
418 -2097151.375, /* 2^21 - 0.625 */
419 -2097151.500, /* 2^21 - 0.5 */
420 -2097151.625, /* 2^21 - 0.375 */
421 -2097151.750, /* 2^21 - 0.25 */
422 -2097151.875, /* 2^21 - 0.125 */
423 -2097152.00, /* 2^21 */
424 -2097152.25, /* 2^21 + 0.25 */
425 -2097152.50, /* 2^21 + 0.5 */
426 -2097152.75, /* 2^21 + 0.75 */
427 -2097153.00, /* 2^21 + 1 */
428 -2097153.25, /* 2^21 + 1.25 */
429 -2097153.50, /* 2^21 + 1.5 */
430 -2097153.75, /* 2^21 + 1.75 */
431 -2097154.00, /* 2^21 + 2 */
432
433 -4194302.00, /* 2^22 - 2 */
434 -4194302.25, /* 2^22 - 1.75 */
435 -4194302.50, /* 2^22 - 1.5 */
436 -4194302.75, /* 2^22 - 1.25 */
437 -4194303.00, /* 2^22 - 1 */
438 -4194303.25, /* 2^22 - 0.75 */
439 -4194303.50, /* 2^22 - 0.5 */
440 -4194303.75, /* 2^22 - 0.25 */
441 -4194304.0, /* 2^22 */
442 -4194304.5, /* 2^22 + 0.5 */
443 -4194305.0, /* 2^22 + 1 */
444 -4194305.5, /* 2^22 + 1.5 */
445 -4194306.0, /* 2^22 + 2 */
446
447 -8388604.0, /* 2^23 - 4 */
448 -8388604.5, /* 2^23 - 3.5 */
449 -8388605.0, /* 2^23 - 3 */
450 -8388605.5, /* 2^23 - 2.5 */
451 -8388606.0, /* 2^23 - 2 */
452 -8388606.5, /* 2^23 - 1.5 */
453 -8388607.0, /* 2^23 - 1 */
454 -8388607.5, /* 2^23 - 0.5 */
455 -8388608.0, /* 2^23 */
456 -8388609.0, /* 2^23 + 1 */
457 -8388610.0, /* 2^23 + 2 */
458 -8388611.0, /* 2^23 + 3 */
459 -8388612.0, /* 2^23 + 4 */
460
461 -16777208.0, /* 2^24 - 8 */
462 -16777209.0, /* 2^24 - 7 */
463 -16777210.0, /* 2^24 - 6 */
464 -16777211.0, /* 2^24 - 5 */
465 -16777212.0, /* 2^24 - 4 */
466 -16777213.0, /* 2^24 - 3 */
467 -16777214.0, /* 2^24 - 2 */
468 -16777215.0, /* 2^24 - 1 */
469 -16777216.0, /* 2^24 */
470 -16777218.0, /* 2^24 + 2 */
471 -16777220.0, /* 2^24 + 4 */
472 -16777222.0, /* 2^24 + 6 */
473 -16777224.0, /* 2^24 + 8 */
474
475 -0x1.fffffep100f, /* large integer with full mantissa */
476
477 /* a few random numbers*/
478 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.5, -600.0, 1.0
479};
480
481static float float_results_trunc[FLOAT_CASES] = {
482 HUGE_VALF,
483 -HUGE_VALF,
484 __builtin_nanf(""),
485 -__builtin_nanf(""),
486 __builtin_nanf("0xdeadbe"),
487 -__builtin_nanf("0xdeadbe"),
488
489 0.0,
490 0.0,
491 0.0,
492 0.0,
493 0.0,
494 0.0,
495 0.0,
496 1.0,
497 1.0,
498 1.0,
499 1.0,
500 1.0,
501 1.0,
502 2.0,
503 2.0,
504 2.0,
505 2.0,
506 2.0,
507 2.0,
508 3.0,
509 3.0,
510 3.0,
511 3.0,
512 3.0,
513 3.0,
514 4.0,
515 4.0,
516
517 2097150.000, /* 2^21 - 2 */
518 2097150.000, /* 2^21 - 1.875 */
519 2097150.000, /* 2^21 - 1.75 */
520 2097150.000, /* 2^21 - 1.625 */
521 2097150.000, /* 2^21 - 1.5 */
522 2097150.000, /* 2^21 - 1.375 */
523 2097150.000, /* 2^21 - 1.25 */
524 2097150.000, /* 2^21 - 1.125 */
525 2097151.000, /* 2^21 - 1 */
526 2097151.000, /* 2^21 - 0.875 */
527 2097151.000, /* 2^21 - 0.75 */
528 2097151.000, /* 2^21 - 0.625 */
529 2097151.000, /* 2^21 - 0.5 */
530 2097151.000, /* 2^21 - 0.375 */
531 2097151.000, /* 2^21 - 0.25 */
532 2097151.000, /* 2^21 - 0.125 */
533 2097152.00, /* 2^21 */
534 2097152.00, /* 2^21 + 0.25 */
535 2097152.00, /* 2^21 + 0.5 */
536 2097152.00, /* 2^21 + 0.75 */
537 2097153.00, /* 2^21 + 1 */
538 2097153.00, /* 2^21 + 1.25 */
539 2097153.00, /* 2^21 + 1.5 */
540 2097153.00, /* 2^21 + 1.75 */
541 2097154.00, /* 2^21 + 2 */
542
543 4194302.00, /* 2^22 - 2 */
544 4194302.00, /* 2^22 - 1.75 */
545 4194302.00, /* 2^22 - 1.5 */
546 4194302.00, /* 2^22 - 1.25 */
547 4194303.00, /* 2^22 - 1 */
548 4194303.00, /* 2^22 - 0.75 */
549 4194303.00, /* 2^22 - 0.5 */
550 4194303.00, /* 2^22 - 0.25 */
551 4194304.0, /* 2^22 */
552 4194304.0, /* 2^22 + 0.5 */
553 4194305.0, /* 2^22 + 1 */
554 4194305.0, /* 2^22 + 1.5 */
555 4194306.0, /* 2^22 + 2 */
556
557 8388604.0, /* 2^23 - 4 */
558 8388604.0, /* 2^23 - 3.5 */
559 8388605.0, /* 2^23 - 3 */
560 8388605.0, /* 2^23 - 2.5 */
561 8388606.0, /* 2^23 - 2 */
562 8388606.0, /* 2^23 - 1.5 */
563 8388607.0, /* 2^23 - 1 */
564 8388607.0, /* 2^23 - 0.5 */
565 8388608.0, /* 2^23 */
566 8388609.0, /* 2^23 + 1 */
567 8388610.0, /* 2^23 + 2 */
568 8388611.0, /* 2^23 + 3 */
569 8388612.0, /* 2^23 + 4 */
570
571 16777208.0, /* 2^24 - 8 */
572 16777209.0, /* 2^24 - 7 */
573 16777210.0, /* 2^24 - 6 */
574 16777211.0, /* 2^24 - 5 */
575 16777212.0, /* 2^24 - 4 */
576 16777213.0, /* 2^24 - 3 */
577 16777214.0, /* 2^24 - 2 */
578 16777215.0, /* 2^24 - 1 */
579 16777216.0, /* 2^24 */
580 16777218.0, /* 2^24 + 2 */
581 16777220.0, /* 2^24 + 4 */
582 16777222.0, /* 2^24 + 6 */
583 16777224.0, /* 2^24 + 8 */
584
585 0x1.fffffep100f, /* large integer with full mantissa */
586
587 /* Same as above but negative */
588
589 -0.0,
590 -0.0,
591 -0.0,
592 -0.0,
593 -0.0,
594 -0.0,
595 -0.0,
596 -1.0,
597 -1.0,
598 -1.0,
599 -1.0,
600 -1.0,
601 -1.0,
602 -2.0,
603 -2.0,
604 -2.0,
605 -2.0,
606 -2.0,
607 -2.0,
608 -3.0,
609 -3.0,
610 -3.0,
611 -3.0,
612 -3.0,
613 -3.0,
614 -4.0,
615 -4.0,
616
617 -2097150.000, /* 2^21 - 2 */
618 -2097150.000, /* 2^21 - 1.875 */
619 -2097150.000, /* 2^21 - 1.75 */
620 -2097150.000, /* 2^21 - 1.625 */
621 -2097150.000, /* 2^21 - 1.5 */
622 -2097150.000, /* 2^21 - 1.375 */
623 -2097150.000, /* 2^21 - 1.25 */
624 -2097150.000, /* 2^21 - 1.125 */
625 -2097151.000, /* 2^21 - 1 */
626 -2097151.000, /* 2^21 - 0.875 */
627 -2097151.000, /* 2^21 - 0.75 */
628 -2097151.000, /* 2^21 - 0.625 */
629 -2097151.000, /* 2^21 - 0.5 */
630 -2097151.000, /* 2^21 - 0.375 */
631 -2097151.000, /* 2^21 - 0.25 */
632 -2097151.000, /* 2^21 - 0.125 */
633 -2097152.00, /* 2^21 */
634 -2097152.00, /* 2^21 + 0.25 */
635 -2097152.00, /* 2^21 + 0.5 */
636 -2097152.00, /* 2^21 + 0.75 */
637 -2097153.00, /* 2^21 + 1 */
638 -2097153.00, /* 2^21 + 1.25 */
639 -2097153.00, /* 2^21 + 1.5 */
640 -2097153.00, /* 2^21 + 1.75 */
641 -2097154.00, /* 2^21 + 2 */
642
643 -4194302.00, /* 2^22 - 2 */
644 -4194302.00, /* 2^22 - 1.75 */
645 -4194302.00, /* 2^22 - 1.5 */
646 -4194302.00, /* 2^22 - 1.25 */
647 -4194303.00, /* 2^22 - 1 */
648 -4194303.00, /* 2^22 - 0.75 */
649 -4194303.00, /* 2^22 - 0.5 */
650 -4194303.00, /* 2^22 - 0.25 */
651 -4194304.0, /* 2^22 */
652 -4194304.0, /* 2^22 + 0.5 */
653 -4194305.0, /* 2^22 + 1 */
654 -4194305.0, /* 2^22 + 1.5 */
655 -4194306.0, /* 2^22 + 2 */
656
657 -8388604.0, /* 2^23 - 4 */
658 -8388604.0, /* 2^23 - 3.5 */
659 -8388605.0, /* 2^23 - 3 */
660 -8388605.0, /* 2^23 - 2.5 */
661 -8388606.0, /* 2^23 - 2 */
662 -8388606.0, /* 2^23 - 1.5 */
663 -8388607.0, /* 2^23 - 1 */
664 -8388607.0, /* 2^23 - 0.5 */
665 -8388608.0, /* 2^23 */
666 -8388609.0, /* 2^23 + 1 */
667 -8388610.0, /* 2^23 + 2 */
668 -8388611.0, /* 2^23 + 3 */
669 -8388612.0, /* 2^23 + 4 */
670
671 -16777208.0, /* 2^24 - 8 */
672 -16777209.0, /* 2^24 - 7 */
673 -16777210.0, /* 2^24 - 6 */
674 -16777211.0, /* 2^24 - 5 */
675 -16777212.0, /* 2^24 - 4 */
676 -16777213.0, /* 2^24 - 3 */
677 -16777214.0, /* 2^24 - 2 */
678 -16777215.0, /* 2^24 - 1 */
679 -16777216.0, /* 2^24 */
680 -16777218.0, /* 2^24 + 2 */
681 -16777220.0, /* 2^24 + 4 */
682 -16777222.0, /* 2^24 + 6 */
683 -16777224.0, /* 2^24 + 8 */
684
685 -0x1.fffffep100f, /* large integer with full mantissa */
686
687 /* a few random numbers*/
688 3.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
689};
690
691static float float_results_round[FLOAT_CASES] = {
692 HUGE_VALF,
693 -HUGE_VALF,
694 __builtin_nanf(""),
695 -__builtin_nanf(""),
696 __builtin_nanf("0xdeadbe"),
697 -__builtin_nanf("0xdeadbe"),
698
699 0.0,
700 0.0, /* smallest denormal > 0 */
701 0.0, /* smallest normal > 0 */
702 0.0,
703 1.0,
704 1.0,
705 1.0,
706 1.0,
707 1.0,
708 1.0,
709 2.0,
710 2.0,
711 2.0,
712 2.0,
713 2.0,
714 2.0,
715 3.0,
716 3.0,
717 3.0,
718 3.0,
719 3.0,
720 3.0,
721 4.0,
722 4.0,
723 4.0,
724 4.0,
725 4.0,
726
727 2097150.000, /* 2^21 - 2 */
728 2097150.000, /* 2^21 - 1.875 */
729 2097150.000, /* 2^21 - 1.75 */
730 2097150.000, /* 2^21 - 1.625 */
731 2097151.000, /* 2^21 - 1.5 */
732 2097151.000, /* 2^21 - 1.375 */
733 2097151.000, /* 2^21 - 1.25 */
734 2097151.000, /* 2^21 - 1.125 */
735 2097151.000, /* 2^21 - 1 */
736 2097151.000, /* 2^21 - 0.875 */
737 2097151.000, /* 2^21 - 0.75 */
738 2097151.000, /* 2^21 - 0.625 */
739 2097152.000, /* 2^21 - 0.5 */
740 2097152.000, /* 2^21 - 0.375 */
741 2097152.000, /* 2^21 - 0.25 */
742 2097152.000, /* 2^21 - 0.125 */
743 2097152.00, /* 2^21 */
744 2097152.00, /* 2^21 + 0.25 */
745 2097153.00, /* 2^21 + 0.5 */
746 2097153.00, /* 2^21 + 0.75 */
747 2097153.00, /* 2^21 + 1 */
748 2097153.00, /* 2^21 + 1.25 */
749 2097154.00, /* 2^21 + 1.5 */
750 2097154.00, /* 2^21 + 1.75 */
751 2097154.00, /* 2^21 + 2 */
752
753 4194302.00, /* 2^22 - 2 */
754 4194302.00, /* 2^22 - 1.75 */
755 4194303.00, /* 2^22 - 1.5 */
756 4194303.00, /* 2^22 - 1.25 */
757 4194303.00, /* 2^22 - 1 */
758 4194303.00, /* 2^22 - 0.75 */
759 4194304.00, /* 2^22 - 0.5 */
760 4194304.00, /* 2^22 - 0.25 */
761 4194304.0, /* 2^22 */
762 4194305.0, /* 2^22 + 0.5 */
763 4194305.0, /* 2^22 + 1 */
764 4194306.0, /* 2^22 + 1.5 */
765 4194306.0, /* 2^22 + 2 */
766
767 8388604.0, /* 2^23 - 4 */
768 8388605.0, /* 2^23 - 3.5 */
769 8388605.0, /* 2^23 - 3 */
770 8388606.0, /* 2^23 - 2.5 */
771 8388606.0, /* 2^23 - 2 */
772 8388607.0, /* 2^23 - 1.5 */
773 8388607.0, /* 2^23 - 1 */
774 8388608.0, /* 2^23 - 0.5 */
775 8388608.0, /* 2^23 */
776 8388609.0, /* 2^23 + 1 */
777 8388610.0, /* 2^23 + 2 */
778 8388611.0, /* 2^23 + 3 */
779 8388612.0, /* 2^23 + 4 */
780
781 16777208.0, /* 2^24 - 8 */
782 16777209.0, /* 2^24 - 7 */
783 16777210.0, /* 2^24 - 6 */
784 16777211.0, /* 2^24 - 5 */
785 16777212.0, /* 2^24 - 4 */
786 16777213.0, /* 2^24 - 3 */
787 16777214.0, /* 2^24 - 2 */
788 16777215.0, /* 2^24 - 1 */
789 16777216.0, /* 2^24 */
790 16777218.0, /* 2^24 + 2 */
791 16777220.0, /* 2^24 + 4 */
792 16777222.0, /* 2^24 + 6 */
793 16777224.0, /* 2^24 + 8 */
794
795 0x1.fffffep100f, /* large integer with full mantissa */
796
797 /* Same as above but negative */
798
799 -0.0,
800 -0.0, /* smallest denormal > 0 */
801 -0.0, /* smallest normal > 0 */
802 -0.0,
803 -1.0,
804 -1.0,
805 -1.0,
806 -1.0,
807 -1.0,
808 -1.0,
809 -2.0,
810 -2.0,
811 -2.0,
812 -2.0,
813 -2.0,
814 -2.0,
815 -3.0,
816 -3.0,
817 -3.0,
818 -3.0,
819 -3.0,
820 -3.0,
821 -4.0,
822 -4.0,
823 -4.0,
824 -4.0,
825 -4.0,
826
827 -2097150.000, /* 2^21 - 2 */
828 -2097150.000, /* 2^21 - 1.875 */
829 -2097150.000, /* 2^21 - 1.75 */
830 -2097150.000, /* 2^21 - 1.625 */
831 -2097151.000, /* 2^21 - 1.5 */
832 -2097151.000, /* 2^21 - 1.375 */
833 -2097151.000, /* 2^21 - 1.25 */
834 -2097151.000, /* 2^21 - 1.125 */
835 -2097151.000, /* 2^21 - 1 */
836 -2097151.000, /* 2^21 - 0.875 */
837 -2097151.000, /* 2^21 - 0.75 */
838 -2097151.000, /* 2^21 - 0.625 */
839 -2097152.000, /* 2^21 - 0.5 */
840 -2097152.000, /* 2^21 - 0.375 */
841 -2097152.000, /* 2^21 - 0.25 */
842 -2097152.000, /* 2^21 - 0.125 */
843 -2097152.00, /* 2^21 */
844 -2097152.00, /* 2^21 + 0.25 */
845 -2097153.00, /* 2^21 + 0.5 */
846 -2097153.00, /* 2^21 + 0.75 */
847 -2097153.00, /* 2^21 + 1 */
848 -2097153.00, /* 2^21 + 1.25 */
849 -2097154.00, /* 2^21 + 1.5 */
850 -2097154.00, /* 2^21 + 1.75 */
851 -2097154.00, /* 2^21 + 2 */
852
853 -4194302.00, /* 2^22 - 2 */
854 -4194302.00, /* 2^22 - 1.75 */
855 -4194303.00, /* 2^22 - 1.5 */
856 -4194303.00, /* 2^22 - 1.25 */
857 -4194303.00, /* 2^22 - 1 */
858 -4194303.00, /* 2^22 - 0.75 */
859 -4194304.00, /* 2^22 - 0.5 */
860 -4194304.00, /* 2^22 - 0.25 */
861 -4194304.0, /* 2^22 */
862 -4194305.0, /* 2^22 + 0.5 */
863 -4194305.0, /* 2^22 + 1 */
864 -4194306.0, /* 2^22 + 1.5 */
865 -4194306.0, /* 2^22 + 2 */
866
867 -8388604.0, /* 2^23 - 4 */
868 -8388605.0, /* 2^23 - 3.5 */
869 -8388605.0, /* 2^23 - 3 */
870 -8388606.0, /* 2^23 - 2.5 */
871 -8388606.0, /* 2^23 - 2 */
872 -8388607.0, /* 2^23 - 1.5 */
873 -8388607.0, /* 2^23 - 1 */
874 -8388608.0, /* 2^23 - 0.5 */
875 -8388608.0, /* 2^23 */
876 -8388609.0, /* 2^23 + 1 */
877 -8388610.0, /* 2^23 + 2 */
878 -8388611.0, /* 2^23 + 3 */
879 -8388612.0, /* 2^23 + 4 */
880
881 -16777208.0, /* 2^24 - 8 */
882 -16777209.0, /* 2^24 - 7 */
883 -16777210.0, /* 2^24 - 6 */
884 -16777211.0, /* 2^24 - 5 */
885 -16777212.0, /* 2^24 - 4 */
886 -16777213.0, /* 2^24 - 3 */
887 -16777214.0, /* 2^24 - 2 */
888 -16777215.0, /* 2^24 - 1 */
889 -16777216.0, /* 2^24 */
890 -16777218.0, /* 2^24 + 2 */
891 -16777220.0, /* 2^24 + 4 */
892 -16777222.0, /* 2^24 + 6 */
893 -16777224.0, /* 2^24 + 8 */
894
895 -0x1.fffffep100f, /* large integer with full mantissa */
896
897 /* a few random numbers*/
898 4.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1081.0, -600.0, 1.0
899};
900
901static float float_results_nearbyint[FLOAT_CASES] = {
902 HUGE_VALF,
903 -HUGE_VALF,
904 __builtin_nanf(""),
905 -__builtin_nanf(""),
906 __builtin_nanf("0xdeadbe"),
907 -__builtin_nanf("0xdeadbe"),
908
909 0.0,
910 0.0, /* smallest denormal > 0 */
911 0.0, /* smallest normal > 0 */
912 0.0,
913 0.0,
914 1.0,
915 1.0,
916 1.0,
917 1.0,
918 1.0,
919 2.0,
920 2.0,
921 2.0,
922 2.0,
923 2.0,
924 2.0,
925 2.0,
926 3.0,
927 3.0,
928 3.0,
929 3.0,
930 3.0,
931 4.0,
932 4.0,
933 4.0,
934 4.0,
935 4.0,
936
937 2097150.000, /* 2^21 - 2 */
938 2097150.000, /* 2^21 - 1.875 */
939 2097150.000, /* 2^21 - 1.75 */
940 2097150.000, /* 2^21 - 1.625 */
941 2097150.000, /* 2^21 - 1.5 */
942 2097151.000, /* 2^21 - 1.375 */
943 2097151.000, /* 2^21 - 1.25 */
944 2097151.000, /* 2^21 - 1.125 */
945 2097151.000, /* 2^21 - 1 */
946 2097151.000, /* 2^21 - 0.875 */
947 2097151.000, /* 2^21 - 0.75 */
948 2097151.000, /* 2^21 - 0.625 */
949 2097152.000, /* 2^21 - 0.5 */
950 2097152.000, /* 2^21 - 0.375 */
951 2097152.000, /* 2^21 - 0.25 */
952 2097152.000, /* 2^21 - 0.125 */
953 2097152.00, /* 2^21 */
954 2097152.00, /* 2^21 + 0.25 */
955 2097152.00, /* 2^21 + 0.5 */
956 2097153.00, /* 2^21 + 0.75 */
957 2097153.00, /* 2^21 + 1 */
958 2097153.00, /* 2^21 + 1.25 */
959 2097154.00, /* 2^21 + 1.5 */
960 2097154.00, /* 2^21 + 1.75 */
961 2097154.00, /* 2^21 + 2 */
962
963 4194302.00, /* 2^22 - 2 */
964 4194302.00, /* 2^22 - 1.75 */
965 4194302.00, /* 2^22 - 1.5 */
966 4194303.00, /* 2^22 - 1.25 */
967 4194303.00, /* 2^22 - 1 */
968 4194303.00, /* 2^22 - 0.75 */
969 4194304.00, /* 2^22 - 0.5 */
970 4194304.0, /* 2^22 - 0.25 */
971 4194304.0, /* 2^22 */
972 4194304.0, /* 2^22 + 0.5 */
973 4194305.0, /* 2^22 + 1 */
974 4194306.0, /* 2^22 + 1.5 */
975 4194306.0, /* 2^22 + 2 */
976
977 8388604.0, /* 2^23 - 4 */
978 8388604.0, /* 2^23 - 3.5 */
979 8388605.0, /* 2^23 - 3 */
980 8388606.0, /* 2^23 - 2.5 */
981 8388606.0, /* 2^23 - 2 */
982 8388606.0, /* 2^23 - 1.5 */
983 8388607.0, /* 2^23 - 1 */
984 8388608.0, /* 2^23 - 0.5 */
985 8388608.0, /* 2^23 */
986 8388609.0, /* 2^23 + 1 */
987 8388610.0, /* 2^23 + 2 */
988 8388611.0, /* 2^23 + 3 */
989 8388612.0, /* 2^23 + 4 */
990
991 16777208.0, /* 2^24 - 8 */
992 16777209.0, /* 2^24 - 7 */
993 16777210.0, /* 2^24 - 6 */
994 16777211.0, /* 2^24 - 5 */
995 16777212.0, /* 2^24 - 4 */
996 16777213.0, /* 2^24 - 3 */
997 16777214.0, /* 2^24 - 2 */
998 16777215.0, /* 2^24 - 1 */
999 16777216.0, /* 2^24 */
1000 16777218.0, /* 2^24 + 2 */
1001 16777220.0, /* 2^24 + 4 */
1002 16777222.0, /* 2^24 + 6 */
1003 16777224.0, /* 2^24 + 8 */
1004
1005 0x1.fffffep100f, /* large integer with full mantissa */
1006
1007 /* Same as above but negative */
1008
1009 -0.0,
1010 -0.0, /* smallest denormal > 0 */
1011 -0.0, /* smallest normal > 0 */
1012 -0.0,
1013 -0.0,
1014 -1.0,
1015 -1.0,
1016 -1.0,
1017 -1.0,
1018 -1.0,
1019 -2.0,
1020 -2.0,
1021 -2.0,
1022 -2.0,
1023 -2.0,
1024 -2.0,
1025 -2.0,
1026 -3.0,
1027 -3.0,
1028 -3.0,
1029 -3.0,
1030 -3.0,
1031 -4.0,
1032 -4.0,
1033 -4.0,
1034 -4.0,
1035 -4.0,
1036
1037 -2097150.000, /* 2^21 - 2 */
1038 -2097150.000, /* 2^21 - 1.875 */
1039 -2097150.000, /* 2^21 - 1.75 */
1040 -2097150.000, /* 2^21 - 1.625 */
1041 -2097150.000, /* 2^21 - 1.5 */
1042 -2097151.000, /* 2^21 - 1.375 */
1043 -2097151.000, /* 2^21 - 1.25 */
1044 -2097151.000, /* 2^21 - 1.125 */
1045 -2097151.000, /* 2^21 - 1 */
1046 -2097151.000, /* 2^21 - 0.875 */
1047 -2097151.000, /* 2^21 - 0.75 */
1048 -2097151.000, /* 2^21 - 0.625 */
1049 -2097152.000, /* 2^21 - 0.5 */
1050 -2097152.000, /* 2^21 - 0.375 */
1051 -2097152.000, /* 2^21 - 0.25 */
1052 -2097152.000, /* 2^21 - 0.125 */
1053 -2097152.00, /* 2^21 */
1054 -2097152.00, /* 2^21 + 0.25 */
1055 -2097152.00, /* 2^21 + 0.5 */
1056 -2097153.00, /* 2^21 + 0.75 */
1057 -2097153.00, /* 2^21 + 1 */
1058 -2097153.00, /* 2^21 + 1.25 */
1059 -2097154.00, /* 2^21 + 1.5 */
1060 -2097154.00, /* 2^21 + 1.75 */
1061 -2097154.00, /* 2^21 + 2 */
1062
1063 -4194302.00, /* 2^22 - 2 */
1064 -4194302.00, /* 2^22 - 1.75 */
1065 -4194302.00, /* 2^22 - 1.5 */
1066 -4194303.00, /* 2^22 - 1.25 */
1067 -4194303.00, /* 2^22 - 1 */
1068 -4194303.00, /* 2^22 - 0.75 */
1069 -4194304.00, /* 2^22 - 0.5 */
1070 -4194304.0, /* 2^22 - 0.25 */
1071 -4194304.0, /* 2^22 */
1072 -4194304.0, /* 2^22 + 0.5 */
1073 -4194305.0, /* 2^22 + 1 */
1074 -4194306.0, /* 2^22 + 1.5 */
1075 -4194306.0, /* 2^22 + 2 */
1076
1077 -8388604.0, /* 2^23 - 4 */
1078 -8388604.0, /* 2^23 - 3.5 */
1079 -8388605.0, /* 2^23 - 3 */
1080 -8388606.0, /* 2^23 - 2.5 */
1081 -8388606.0, /* 2^23 - 2 */
1082 -8388606.0, /* 2^23 - 1.5 */
1083 -8388607.0, /* 2^23 - 1 */
1084 -8388608.0, /* 2^23 - 0.5 */
1085 -8388608.0, /* 2^23 */
1086 -8388609.0, /* 2^23 + 1 */
1087 -8388610.0, /* 2^23 + 2 */
1088 -8388611.0, /* 2^23 + 3 */
1089 -8388612.0, /* 2^23 + 4 */
1090
1091 -16777208.0, /* 2^24 - 8 */
1092 -16777209.0, /* 2^24 - 7 */
1093 -16777210.0, /* 2^24 - 6 */
1094 -16777211.0, /* 2^24 - 5 */
1095 -16777212.0, /* 2^24 - 4 */
1096 -16777213.0, /* 2^24 - 3 */
1097 -16777214.0, /* 2^24 - 2 */
1098 -16777215.0, /* 2^24 - 1 */
1099 -16777216.0, /* 2^24 */
1100 -16777218.0, /* 2^24 + 2 */
1101 -16777220.0, /* 2^24 + 4 */
1102 -16777222.0, /* 2^24 + 6 */
1103 -16777224.0, /* 2^24 + 8 */
1104
1105 -0x1.fffffep100f, /* large integer with full mantissa */
1106
1107 /* a few random numbers*/
1108 4.0, -2.0, 100.0, 50.0, -1024.0, 0.0, 768.0, 1080.0, -600.0, 1.0
1109};
1110
1111PCUT_TEST(identity)
1112{
1113 for (int i = 0; i < FLOAT_CASES; i++) {
1114 uint32_t f1 = fint(float_arguments[i]);
1115 uint32_t f2 = fint(float_identity[i]);
1116 if (f1 != f2) {
1117 PCUT_ASSERTION_FAILED("case %d: 0x%08x != 0x%08x\n", i, f1, f2);
1118 }
1119 }
1120}
1121
1122PCUT_TEST(truncf)
1123{
1124 for (int i = 0; i < FLOAT_CASES; i++) {
1125 uint32_t f1 = fint(truncf(float_arguments[i]));
1126 uint32_t f2 = fint(float_results_trunc[i]);
1127 if (f1 != f2) {
1128 PCUT_ASSERTION_FAILED("case %d: 0x%08x != 0x%08x\n", i, f1, f2);
1129 }
1130 }
1131}
1132
1133PCUT_TEST(trunc)
1134{
1135 for (int i = 0; i < FLOAT_CASES; i++) {
1136 uint64_t f1 = dint(trunc(float_arguments[i]));
1137 uint64_t f2 = dint(float_results_trunc[i]);
1138 if (f1 != f2) {
1139 PCUT_ASSERTION_FAILED("case %d: 0x%016" PRIx64 " != 0x%016" PRIx64 "\n", i, f1, f2);
1140 }
1141 }
1142
1143 // TODO: double test cases
1144}
1145
1146PCUT_TEST(roundf)
1147{
1148 for (int i = 0; i < FLOAT_CASES; i++) {
1149 uint32_t f1 = fint(roundf(float_arguments[i]));
1150 uint32_t f2 = fint(float_results_round[i]);
1151 if (f1 != f2) {
1152 PCUT_ASSERTION_FAILED("case %d: 0x%08x != 0x%08x\n", i, f1, f2);
1153 }
1154 }
1155}
1156
1157PCUT_TEST(round)
1158{
1159 for (int i = 0; i < FLOAT_CASES; i++) {
1160 uint64_t f1 = dint(round(float_arguments[i]));
1161 uint64_t f2 = dint(float_results_round[i]);
1162 if (f1 != f2) {
1163 PCUT_ASSERTION_FAILED("case %d: 0x%016" PRIx64 " != 0x%016" PRIx64 "\n", i, f1, f2);
1164 }
1165 }
1166
1167 // TODO: double test cases
1168}
1169
1170PCUT_TEST(nearbyintf)
1171{
1172 // FIXME: ensure default rounding mode
1173
1174 for (int i = 0; i < FLOAT_CASES; i++) {
1175 uint32_t f1 = fint(nearbyintf(float_arguments[i]));
1176 uint32_t f2 = fint(float_results_nearbyint[i]);
1177 if (f1 != f2) {
1178 PCUT_ASSERTION_FAILED("case %d: 0x%08x != 0x%08x\n", i, f1, f2);
1179 }
1180 }
1181}
1182
1183PCUT_TEST(nearbyint)
1184{
1185 // FIXME: ensure default rounding mode
1186
1187 for (int i = 0; i < FLOAT_CASES; i++) {
1188 uint64_t f1 = dint(nearbyint(float_arguments[i]));
1189 uint64_t f2 = dint(float_results_nearbyint[i]);
1190 if (f1 != f2) {
1191 PCUT_ASSERTION_FAILED("case %d: 0x%016" PRIx64 " != 0x%016" PRIx64 "\n", i, f1, f2);
1192 }
1193 }
1194
1195 // TODO: double test cases
1196}
1197
1198PCUT_EXPORT(rounding);
Note: See TracBrowser for help on using the repository browser.