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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 10d65d70 was 10d65d70, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Use compiler-provided freestanding headers

Standard-compliant C compiler must provide these, so there is no point
in us trying to guess or repeat the correct contents.
This includes <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>,
<stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>.

<stdint.h> and <limits.h> need more work.

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