(INTERNAL_SYSCALL): Add LOAD_REGS_##nr. (LOAD_ARGS_0, LOAD_ARGS_1, LOAD_ARGS_2, LOAD_...
[glibc.git] / math / test-misc.c
blob17ef1d3a58d973bb3ad53d90b85e4e8e3dc5a5bd
1 /* Miscellaneous tests which don't fit anywhere else.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <fenv.h>
21 #include <float.h>
22 #include <ieee754.h>
23 #include <math.h>
24 #include <stdio.h>
25 #include <string.h>
28 int
29 main (void)
31 int result = 0;
33 #ifndef NO_LONG_DOUBLE
35 long double x = 0x100000001ll + (long double) 0.5;
36 long double q;
37 long double r;
39 r = modfl (x, &q);
40 if (q != (long double) 0x100000001ll || r != 0.5)
42 printf ("modfl (%Lg, ...) failed\n", x);
43 result = 1;
47 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 96
49 long double x;
50 long double m;
51 long double r;
52 int e;
53 int i;
55 # if LDBL_MANT_DIG == 64
56 m = 0xf.fffffffffffffffp-4L;
57 # elif LDBL_MANT_DIG == 113
58 m = 0x1.ffffffffffffffffffffffffffffp-1L;
59 # else
60 # error "Please adjust"
61 # endif
63 for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
65 printf ("2^%d: ", i);
67 r = frexpl (x, &e);
68 if (r != m)
70 printf ("mantissa incorrect: %.20La\n", r);
71 result = 1;
72 continue;
74 if (e != i)
76 printf ("exponent wrong %d (%.20Lg)\n", e, x);
77 result = 1;
78 continue;
80 puts ("ok");
83 for (i = LDBL_MIN_EXP, x = LDBL_MIN; i >= LDBL_MIN_EXP - LDBL_MANT_DIG + 1;
84 --i, x /= 2.0L)
86 printf ("2^%d: ", i);
88 r = frexpl (x, &e);
89 if (r != 0.5L)
91 printf ("mantissa incorrect: %.20La\n", r);
92 result = 1;
93 continue;
95 if (e != i)
97 printf ("exponent wrong %d (%.20Lg)\n", e, x);
98 result = 1;
99 continue;
101 puts ("ok");
105 # endif
107 #if 0
109 int e;
110 long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);
112 if (r != 0.5)
114 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
116 result = 1;
118 else if (e != -16444)
120 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
122 result = 1;
125 #endif
126 #endif
129 double x = 0x100000001ll + (double) 0.5;
130 double q;
131 double r;
133 r = modf (x, &q);
134 if (q != (double) 0x100000001ll || r != 0.5)
136 printf ("modf (%g, ...) failed\n", x);
137 result = 1;
142 union ieee754_float v1;
143 union ieee754_float v2;
144 float f;
146 v1.f = f = FLT_MIN;
147 if (fpclassify (f) != FP_NORMAL)
149 printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f));
150 result = 1;
152 f = nextafterf (f, FLT_MIN / 2.0f);
153 if (fpclassify (f) != FP_SUBNORMAL)
155 printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
156 result = 1;
158 v2.f = f = nextafterf (f, FLT_MIN);
159 if (fpclassify (f) != FP_NORMAL)
161 printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
162 fpclassify (f));
163 result = 1;
166 if (v1.ieee.mantissa != v2.ieee.mantissa)
168 printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
169 v1.ieee.mantissa, v2.ieee.mantissa);
170 result = 1;
172 if (v1.ieee.exponent != v2.ieee.exponent)
174 printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
175 v1.ieee.exponent, v2.ieee.exponent);
176 result = 1;
178 if (v1.ieee.negative != v2.ieee.negative)
180 printf ("FLT_MIN: negative differs: %d vs %d\n",
181 v1.ieee.negative, v2.ieee.negative);
182 result = 1;
185 v1.f = f = -FLT_MIN;
186 if (fpclassify (f) != FP_NORMAL)
188 printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f));
189 result = 1;
191 f = nextafterf (f, -FLT_MIN / 2.0f);
192 if (fpclassify (f) != FP_SUBNORMAL)
194 printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
195 result = 1;
197 v2.f = f = nextafterf (f, -FLT_MIN);
198 if (fpclassify (f) != FP_NORMAL)
200 printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
201 fpclassify (f));
202 result = 1;
205 if (v1.ieee.mantissa != v2.ieee.mantissa)
207 printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
208 v1.ieee.mantissa, v2.ieee.mantissa);
209 result = 1;
211 if (v1.ieee.exponent != v2.ieee.exponent)
213 printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
214 v1.ieee.exponent, v2.ieee.exponent);
215 result = 1;
217 if (v1.ieee.negative != v2.ieee.negative)
219 printf ("-FLT_MIN: negative differs: %d vs %d\n",
220 v1.ieee.negative, v2.ieee.negative);
221 result = 1;
224 f = FLT_MAX;
225 if (fpclassify (f) != FP_NORMAL)
227 printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f));
228 result = 1;
230 f = nextafterf (f, INFINITY);
231 if (fpclassify (f) != FP_INFINITE)
233 printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f));
234 result = 1;
237 f = -FLT_MAX;
238 if (fpclassify (f) != FP_NORMAL)
240 printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f));
241 result = 1;
243 f = nextafterf (f, -INFINITY);
244 if (fpclassify (f) != FP_INFINITE)
246 printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f));
247 result = 1;
250 v1.f = f = 0.0625;
251 f = nextafterf (f, 0.0);
252 v2.f = f = nextafterf (f, 1.0);
254 if (v1.ieee.mantissa != v2.ieee.mantissa)
256 printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
257 v1.ieee.mantissa, v2.ieee.mantissa);
258 result = 1;
260 if (v1.ieee.exponent != v2.ieee.exponent)
262 printf ("0.0625f down: exponent differs: %4x vs %4x\n",
263 v1.ieee.exponent, v2.ieee.exponent);
264 result = 1;
266 if (v1.ieee.negative != v2.ieee.negative)
268 printf ("0.0625f down: negative differs: %d vs %d\n",
269 v1.ieee.negative, v2.ieee.negative);
270 result = 1;
273 v1.f = f = 0.0625;
274 f = nextafterf (f, 1.0);
275 v2.f = f = nextafterf (f, 0.0);
277 if (v1.ieee.mantissa != v2.ieee.mantissa)
279 printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
280 v1.ieee.mantissa, v2.ieee.mantissa);
281 result = 1;
283 if (v1.ieee.exponent != v2.ieee.exponent)
285 printf ("0.0625f up: exponent differs: %4x vs %4x\n",
286 v1.ieee.exponent, v2.ieee.exponent);
287 result = 1;
289 if (v1.ieee.negative != v2.ieee.negative)
291 printf ("0.0625f up: negative differs: %d vs %d\n",
292 v1.ieee.negative, v2.ieee.negative);
293 result = 1;
296 v1.f = f = -0.0625;
297 f = nextafterf (f, 0.0);
298 v2.f = f = nextafterf (f, -1.0);
300 if (v1.ieee.mantissa != v2.ieee.mantissa)
302 printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
303 v1.ieee.mantissa, v2.ieee.mantissa);
304 result = 1;
306 if (v1.ieee.exponent != v2.ieee.exponent)
308 printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
309 v1.ieee.exponent, v2.ieee.exponent);
310 result = 1;
312 if (v1.ieee.negative != v2.ieee.negative)
314 printf ("-0.0625f up: negative differs: %d vs %d\n",
315 v1.ieee.negative, v2.ieee.negative);
316 result = 1;
319 v1.f = f = -0.0625;
320 f = nextafterf (f, -1.0);
321 v2.f = f = nextafterf (f, 0.0);
323 if (v1.ieee.mantissa != v2.ieee.mantissa)
325 printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
326 v1.ieee.mantissa, v2.ieee.mantissa);
327 result = 1;
329 if (v1.ieee.exponent != v2.ieee.exponent)
331 printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
332 v1.ieee.exponent, v2.ieee.exponent);
333 result = 1;
335 if (v1.ieee.negative != v2.ieee.negative)
337 printf ("-0.0625f down: negative differs: %d vs %d\n",
338 v1.ieee.negative, v2.ieee.negative);
339 result = 1;
342 v1.f = f = 0.0f;
343 f = nextafterf (f, 1.0);
344 v2.f = nextafterf (f, -1.0);
346 if (v1.ieee.mantissa != v2.ieee.mantissa)
348 printf ("0.0f up: mantissa differs: %8x vs %8x\n",
349 v1.ieee.mantissa, v2.ieee.mantissa);
350 result = 1;
352 if (v1.ieee.exponent != v2.ieee.exponent)
354 printf ("0.0f up: exponent differs: %4x vs %4x\n",
355 v1.ieee.exponent, v2.ieee.exponent);
356 result = 1;
358 if (0 != v2.ieee.negative)
360 printf ("0.0f up: negative differs: 0 vs %d\n",
361 v2.ieee.negative);
362 result = 1;
365 v1.f = f = 0.0f;
366 f = nextafterf (f, -1.0);
367 v2.f = nextafterf (f, 1.0);
369 if (v1.ieee.mantissa != v2.ieee.mantissa)
371 printf ("0.0f down: mantissa differs: %8x vs %8x\n",
372 v1.ieee.mantissa, v2.ieee.mantissa);
373 result = 1;
375 if (v1.ieee.exponent != v2.ieee.exponent)
377 printf ("0.0f down: exponent differs: %4x vs %4x\n",
378 v1.ieee.exponent, v2.ieee.exponent);
379 result = 1;
381 if (1 != v2.ieee.negative)
383 printf ("0.0f down: negative differs: 1 vs %d\n",
384 v2.ieee.negative);
385 result = 1;
388 if (nextafterf (0.0f, INFINITY) != nextafterf (0.0f, 1.0f)
389 || nextafterf (-0.0f, INFINITY) != nextafterf (-0.0f, 1.0f)
390 || nextafterf (0.0f, -INFINITY) != nextafterf (0.0f, -1.0f)
391 || nextafterf (-0.0f, -INFINITY) != nextafterf (-0.0f, -1.0f))
393 printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
394 result = 1;
397 if (nexttowardf (0.0f, INFINITY) != nexttowardf (0.0f, 1.0f)
398 || nexttowardf (-0.0f, INFINITY) != nexttowardf (-0.0f, 1.0f)
399 || nexttowardf (0.0f, -INFINITY) != nexttowardf (0.0f, -1.0f)
400 || nexttowardf (-0.0f, -INFINITY) != nexttowardf (-0.0f, -1.0f))
402 printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
403 result = 1;
408 union ieee754_double v1;
409 union ieee754_double v2;
410 double d;
412 v1.d = d = DBL_MIN;
413 if (fpclassify (d) != FP_NORMAL)
415 printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d));
416 result = 1;
418 d = nextafter (d, DBL_MIN / 2.0);
419 if (fpclassify (d) != FP_SUBNORMAL)
421 printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
422 result = 1;
424 v2.d = d = nextafter (d, DBL_MIN);
425 if (fpclassify (d) != FP_NORMAL)
427 printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
428 fpclassify (d));
429 result = 1;
432 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
434 printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
435 v1.ieee.mantissa0, v2.ieee.mantissa0);
436 result = 1;
438 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
440 printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
441 v1.ieee.mantissa1, v2.ieee.mantissa1);
442 result = 1;
444 if (v1.ieee.exponent != v2.ieee.exponent)
446 printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
447 v1.ieee.exponent, v2.ieee.exponent);
448 result = 1;
450 if (v1.ieee.negative != v2.ieee.negative)
452 printf ("DBL_MIN: negative differs: %d vs %d\n",
453 v1.ieee.negative, v2.ieee.negative);
454 result = 1;
457 v1.d = d = -DBL_MIN;
458 if (fpclassify (d) != FP_NORMAL)
460 printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d));
461 result = 1;
463 d = nextafter (d, -DBL_MIN / 2.0);
464 if (fpclassify (d) != FP_SUBNORMAL)
466 printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
467 result = 1;
469 v2.d = d = nextafter (d, -DBL_MIN);
470 if (fpclassify (d) != FP_NORMAL)
472 printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
473 fpclassify (d));
474 result = 1;
477 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
479 printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
480 v1.ieee.mantissa0, v2.ieee.mantissa0);
481 result = 1;
483 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
485 printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
486 v1.ieee.mantissa1, v2.ieee.mantissa1);
487 result = 1;
489 if (v1.ieee.exponent != v2.ieee.exponent)
491 printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
492 v1.ieee.exponent, v2.ieee.exponent);
493 result = 1;
495 if (v1.ieee.negative != v2.ieee.negative)
497 printf ("-DBL_MIN: negative differs: %d vs %d\n",
498 v1.ieee.negative, v2.ieee.negative);
499 result = 1;
502 d = DBL_MAX;
503 if (fpclassify (d) != FP_NORMAL)
505 printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d));
506 result = 1;
508 d = nextafter (d, INFINITY);
509 if (fpclassify (d) != FP_INFINITE)
511 printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d));
512 result = 1;
515 d = -DBL_MAX;
516 if (fpclassify (d) != FP_NORMAL)
518 printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d));
519 result = 1;
521 d = nextafter (d, -INFINITY);
522 if (fpclassify (d) != FP_INFINITE)
524 printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d));
525 result = 1;
528 v1.d = d = 0.0625;
529 d = nextafter (d, 0.0);
530 v2.d = d = nextafter (d, 1.0);
532 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
534 printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
535 v1.ieee.mantissa0, v2.ieee.mantissa0);
536 result = 1;
538 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
540 printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
541 v1.ieee.mantissa1, v2.ieee.mantissa1);
542 result = 1;
544 if (v1.ieee.exponent != v2.ieee.exponent)
546 printf ("0.0625 down: exponent differs: %4x vs %4x\n",
547 v1.ieee.exponent, v2.ieee.exponent);
548 result = 1;
550 if (v1.ieee.negative != v2.ieee.negative)
552 printf ("0.0625 down: negative differs: %d vs %d\n",
553 v1.ieee.negative, v2.ieee.negative);
554 result = 1;
557 v1.d = d = 0.0625;
558 d = nextafter (d, 1.0);
559 v2.d = d = nextafter (d, 0.0);
561 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
563 printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
564 v1.ieee.mantissa0, v2.ieee.mantissa0);
565 result = 1;
567 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
569 printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
570 v1.ieee.mantissa1, v2.ieee.mantissa1);
571 result = 1;
573 if (v1.ieee.exponent != v2.ieee.exponent)
575 printf ("0.0625 up: exponent differs: %4x vs %4x\n",
576 v1.ieee.exponent, v2.ieee.exponent);
577 result = 1;
579 if (v1.ieee.negative != v2.ieee.negative)
581 printf ("0.0625 up: negative differs: %d vs %d\n",
582 v1.ieee.negative, v2.ieee.negative);
583 result = 1;
586 v1.d = d = -0.0625;
587 d = nextafter (d, 0.0);
588 v2.d = d = nextafter (d, -1.0);
590 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
592 printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
593 v1.ieee.mantissa0, v2.ieee.mantissa0);
594 result = 1;
596 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
598 printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
599 v1.ieee.mantissa1, v2.ieee.mantissa1);
600 result = 1;
602 if (v1.ieee.exponent != v2.ieee.exponent)
604 printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
605 v1.ieee.exponent, v2.ieee.exponent);
606 result = 1;
608 if (v1.ieee.negative != v2.ieee.negative)
610 printf ("-0.0625 up: negative differs: %d vs %d\n",
611 v1.ieee.negative, v2.ieee.negative);
612 result = 1;
615 v1.d = d = -0.0625;
616 d = nextafter (d, -1.0);
617 v2.d = d = nextafter (d, 0.0);
619 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
621 printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
622 v1.ieee.mantissa0, v2.ieee.mantissa0);
623 result = 1;
625 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
627 printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
628 v1.ieee.mantissa1, v2.ieee.mantissa1);
629 result = 1;
631 if (v1.ieee.exponent != v2.ieee.exponent)
633 printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
634 v1.ieee.exponent, v2.ieee.exponent);
635 result = 1;
637 if (v1.ieee.negative != v2.ieee.negative)
639 printf ("-0.0625 down: negative differs: %d vs %d\n",
640 v1.ieee.negative, v2.ieee.negative);
641 result = 1;
644 v1.d = d = 0.0;
645 d = nextafter (d, 1.0);
646 v2.d = nextafter (d, -1.0);
648 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
650 printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
651 v1.ieee.mantissa0, v2.ieee.mantissa0);
652 result = 1;
654 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
656 printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
657 v1.ieee.mantissa1, v2.ieee.mantissa1);
658 result = 1;
660 if (v1.ieee.exponent != v2.ieee.exponent)
662 printf ("0.0 up: exponent differs: %4x vs %4x\n",
663 v1.ieee.exponent, v2.ieee.exponent);
664 result = 1;
666 if (0 != v2.ieee.negative)
668 printf ("0.0 up: negative differs: 0 vs %d\n",
669 v2.ieee.negative);
670 result = 1;
673 v1.d = d = 0.0;
674 d = nextafter (d, -1.0);
675 v2.d = nextafter (d, 1.0);
677 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
679 printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
680 v1.ieee.mantissa0, v2.ieee.mantissa0);
681 result = 1;
683 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
685 printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
686 v1.ieee.mantissa1, v2.ieee.mantissa1);
687 result = 1;
689 if (v1.ieee.exponent != v2.ieee.exponent)
691 printf ("0.0 down: exponent differs: %4x vs %4x\n",
692 v1.ieee.exponent, v2.ieee.exponent);
693 result = 1;
695 if (1 != v2.ieee.negative)
697 printf ("0.0 down: negative differs: 1 vs %d\n",
698 v2.ieee.negative);
699 result = 1;
702 if (nextafter (0.0, INFINITY) != nextafter (0.0, 1.0)
703 || nextafter (-0.0, INFINITY) != nextafter (-0.0, 1.0)
704 || nextafter (0.0, -INFINITY) != nextafter (0.0, -1.0)
705 || nextafter (-0.0, -INFINITY) != nextafter (-0.0, -1.0))
707 printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
708 result = 1;
711 if (nexttoward (0.0, INFINITY) != nexttoward (0.0, 1.0)
712 || nexttoward (-0.0, INFINITY) != nexttoward (-0.0, 1.0)
713 || nexttoward (0.0, -INFINITY) != nexttoward (0.0, -1.0)
714 || nexttoward (-0.0, -INFINITY) != nexttoward (-0.0, -1.0))
716 printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
717 result = 1;
721 #ifndef NO_LONG_DOUBLE
723 union ieee854_long_double v1;
724 union ieee854_long_double v2;
725 long double ld;
727 v1.d = ld = LDBL_MIN;
728 if (fpclassify (ld) != FP_NORMAL)
730 printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld));
731 result = 1;
733 ld = nextafterl (ld, LDBL_MIN / 2.0);
734 if (fpclassify (ld) != FP_SUBNORMAL)
736 printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
737 fpclassify (ld), ld);
738 result = 1;
740 v2.d = ld = nextafterl (ld, LDBL_MIN);
741 if (fpclassify (ld) != FP_NORMAL)
743 printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
744 fpclassify (ld), ld);
745 result = 1;
748 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
750 printf ("LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
751 v1.ieee.mantissa0, v2.ieee.mantissa0);
752 result = 1;
754 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
756 printf ("LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
757 v1.ieee.mantissa1, v2.ieee.mantissa1);
758 result = 1;
760 if (v1.ieee.exponent != v2.ieee.exponent)
762 printf ("LDBL_MIN: exponent differs: %4x vs %4x\n",
763 v1.ieee.exponent, v2.ieee.exponent);
764 result = 1;
766 if (v1.ieee.negative != v2.ieee.negative)
768 printf ("LDBL_MIN: negative differs: %d vs %d\n",
769 v1.ieee.negative, v2.ieee.negative);
770 result = 1;
773 v1.d = ld = -LDBL_MIN;
774 if (fpclassify (ld) != FP_NORMAL)
776 printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld));
777 result = 1;
779 ld = nextafterl (ld, -LDBL_MIN / 2.0);
780 if (fpclassify (ld) != FP_SUBNORMAL)
782 printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
783 fpclassify (ld), ld);
784 result = 1;
786 v2.d = ld = nextafterl (ld, -LDBL_MIN);
787 if (fpclassify (ld) != FP_NORMAL)
789 printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
790 fpclassify (ld), ld);
791 result = 1;
794 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
796 printf ("-LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
797 v1.ieee.mantissa0, v2.ieee.mantissa0);
798 result = 1;
800 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
802 printf ("-LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
803 v1.ieee.mantissa1, v2.ieee.mantissa1);
804 result = 1;
806 if (v1.ieee.exponent != v2.ieee.exponent)
808 printf ("-LDBL_MIN: exponent differs: %4x vs %4x\n",
809 v1.ieee.exponent, v2.ieee.exponent);
810 result = 1;
812 if (v1.ieee.negative != v2.ieee.negative)
814 printf ("-LDBL_MIN: negative differs: %d vs %d\n",
815 v1.ieee.negative, v2.ieee.negative);
816 result = 1;
819 ld = LDBL_MAX;
820 if (fpclassify (ld) != FP_NORMAL)
822 printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld));
823 result = 1;
825 ld = nextafterl (ld, INFINITY);
826 if (fpclassify (ld) != FP_INFINITE)
828 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld));
829 result = 1;
832 ld = -LDBL_MAX;
833 if (fpclassify (ld) != FP_NORMAL)
835 printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld));
836 result = 1;
838 ld = nextafterl (ld, -INFINITY);
839 if (fpclassify (ld) != FP_INFINITE)
841 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
842 fpclassify (ld));
843 result = 1;
846 v1.d = ld = 0.0625;
847 ld = nextafterl (ld, 0.0);
848 v2.d = ld = nextafterl (ld, 1.0);
850 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
852 printf ("0.0625L down: mantissa0 differs: %8x vs %8x\n",
853 v1.ieee.mantissa0, v2.ieee.mantissa0);
854 result = 1;
856 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
858 printf ("0.0625L down: mantissa1 differs: %8x vs %8x\n",
859 v1.ieee.mantissa1, v2.ieee.mantissa1);
860 result = 1;
862 if (v1.ieee.exponent != v2.ieee.exponent)
864 printf ("0.0625L down: exponent differs: %4x vs %4x\n",
865 v1.ieee.exponent, v2.ieee.exponent);
866 result = 1;
868 if (v1.ieee.negative != v2.ieee.negative)
870 printf ("0.0625L down: negative differs: %d vs %d\n",
871 v1.ieee.negative, v2.ieee.negative);
872 result = 1;
875 v1.d = ld = 0.0625;
876 ld = nextafterl (ld, 1.0);
877 v2.d = ld = nextafterl (ld, 0.0);
879 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
881 printf ("0.0625L up: mantissa0 differs: %8x vs %8x\n",
882 v1.ieee.mantissa0, v2.ieee.mantissa0);
883 result = 1;
885 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
887 printf ("0.0625L up: mantissa1 differs: %8x vs %8x\n",
888 v1.ieee.mantissa1, v2.ieee.mantissa1);
889 result = 1;
891 if (v1.ieee.exponent != v2.ieee.exponent)
893 printf ("0.0625L up: exponent differs: %4x vs %4x\n",
894 v1.ieee.exponent, v2.ieee.exponent);
895 result = 1;
897 if (v1.ieee.negative != v2.ieee.negative)
899 printf ("0.0625L up: negative differs: %d vs %d\n",
900 v1.ieee.negative, v2.ieee.negative);
901 result = 1;
904 v1.d = ld = -0.0625;
905 ld = nextafterl (ld, 0.0);
906 v2.d = ld = nextafterl (ld, -1.0);
908 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
910 printf ("-0.0625L up: mantissa0 differs: %8x vs %8x\n",
911 v1.ieee.mantissa0, v2.ieee.mantissa0);
912 result = 1;
914 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
916 printf ("-0.0625L up: mantissa1 differs: %8x vs %8x\n",
917 v1.ieee.mantissa1, v2.ieee.mantissa1);
918 result = 1;
920 if (v1.ieee.exponent != v2.ieee.exponent)
922 printf ("-0.0625L up: exponent differs: %4x vs %4x\n",
923 v1.ieee.exponent, v2.ieee.exponent);
924 result = 1;
926 if (v1.ieee.negative != v2.ieee.negative)
928 printf ("-0.0625L up: negative differs: %d vs %d\n",
929 v1.ieee.negative, v2.ieee.negative);
930 result = 1;
933 v1.d = ld = -0.0625;
934 ld = nextafterl (ld, -1.0);
935 v2.d = ld = nextafterl (ld, 0.0);
937 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
939 printf ("-0.0625L down: mantissa0 differs: %8x vs %8x\n",
940 v1.ieee.mantissa0, v2.ieee.mantissa0);
941 result = 1;
943 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
945 printf ("-0.0625L down: mantissa1 differs: %8x vs %8x\n",
946 v1.ieee.mantissa1, v2.ieee.mantissa1);
947 result = 1;
949 if (v1.ieee.exponent != v2.ieee.exponent)
951 printf ("-0.0625L down: exponent differs: %4x vs %4x\n",
952 v1.ieee.exponent, v2.ieee.exponent);
953 result = 1;
955 if (v1.ieee.negative != v2.ieee.negative)
957 printf ("-0.0625L down: negative differs: %d vs %d\n",
958 v1.ieee.negative, v2.ieee.negative);
959 result = 1;
962 v1.d = ld = 0.0;
963 ld = nextafterl (ld, 1.0);
964 v2.d = nextafterl (ld, -1.0);
966 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
968 printf ("0.0L up: mantissa0 differs: %8x vs %8x\n",
969 v1.ieee.mantissa0, v2.ieee.mantissa0);
970 result = 1;
972 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
974 printf ("0.0L up: mantissa1 differs: %8x vs %8x\n",
975 v1.ieee.mantissa1, v2.ieee.mantissa1);
976 result = 1;
978 if (v1.ieee.exponent != v2.ieee.exponent)
980 printf ("0.0L up: exponent differs: %4x vs %4x\n",
981 v1.ieee.exponent, v2.ieee.exponent);
982 result = 1;
984 if (0 != v2.ieee.negative)
986 printf ("0.0L up: negative differs: 0 vs %d\n",
987 v2.ieee.negative);
988 result = 1;
991 v1.d = ld = 0.0;
992 ld = nextafterl (ld, -1.0);
993 v2.d = nextafterl (ld, 1.0);
995 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
997 printf ("0.0L down: mantissa0 differs: %8x vs %8x\n",
998 v1.ieee.mantissa0, v2.ieee.mantissa0);
999 result = 1;
1001 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
1003 printf ("0.0L down: mantissa1 differs: %8x vs %8x\n",
1004 v1.ieee.mantissa1, v2.ieee.mantissa1);
1005 result = 1;
1007 if (v1.ieee.exponent != v2.ieee.exponent)
1009 printf ("0.0L down: exponent differs: %4x vs %4x\n",
1010 v1.ieee.exponent, v2.ieee.exponent);
1011 result = 1;
1013 if (1 != v2.ieee.negative)
1015 printf ("0.0L down: negative differs: 1 vs %d\n",
1016 v2.ieee.negative);
1017 result = 1;
1020 if (nextafterl (0.0, INFINITY) != nextafterl (0.0, 1.0)
1021 || nextafterl (-0.0, INFINITY) != nextafterl (-0.0, 1.0)
1022 || nextafterl (0.0, -INFINITY) != nextafterl (0.0, -1.0)
1023 || nextafterl (-0.0, -INFINITY) != nextafterl (-0.0, -1.0))
1025 printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
1026 result = 1;
1029 if (nexttowardl (0.0L, INFINITY) != nexttowardl (0.0L, 1.0L)
1030 || nexttowardl (-0.0L, INFINITY) != nexttowardl (-0.0L, 1.0L)
1031 || nexttowardl (0.0L, -INFINITY) != nexttowardl (0.0L, -1.0L)
1032 || nexttowardl (-0.0L, -INFINITY) != nexttowardl (-0.0L, -1.0L))
1034 printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
1035 result = 1;
1038 #endif
1040 if (! isnormal (FLT_MIN))
1042 puts ("isnormal (FLT_MIN) failed");
1043 result = 1;
1045 if (! isnormal (DBL_MIN))
1047 puts ("isnormal (DBL_MIN) failed");
1048 result = 1;
1050 #ifndef NO_LONG_DOUBLE
1051 if (! isnormal (LDBL_MIN))
1053 puts ("isnormal (LDBL_MIN) failed");
1054 result = 1;
1056 #endif
1058 #ifdef __i386__
1059 /* This is a test for the strange long doubles in x86 FPUs. */
1061 union
1063 char b[10];
1064 long double d;
1065 } u =
1066 { .b = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
1068 if (fpclassify (u.d) != FP_NORMAL)
1070 printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
1071 fpclassify (u.d), u.d);
1072 result = 1;
1076 /* Special NaNs in x86 long double. Test for scalbl. */
1078 union
1080 char b[10];
1081 long double d;
1082 } u =
1083 { .b = { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
1084 long double r;
1086 r = scalbl (u.d, 0.0);
1087 if (!isnan (r))
1089 puts ("scalbl(NaN, 0) does not return NaN");
1090 result = 1;
1092 else if (memcmp (&r, &u.d, sizeof (double)) != 0)
1094 puts ("scalbl(NaN, 0) does not return the same NaN");
1095 result = 1;
1098 #endif
1100 #ifndef NO_LONG_DOUBLE
1102 long double r;
1104 feclearexcept (FE_ALL_EXCEPT);
1105 r = scalbl (LDBL_MIN, 2147483647);
1106 if (! isinf (r))
1108 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
1109 result = 1;
1111 else if (signbit (r) != 0)
1113 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
1114 result = 1;
1116 else if (fetestexcept (FE_UNDERFLOW))
1118 puts ("scalbl(NaN, 0) raises underflow exception");
1119 result = 1;
1122 feclearexcept (FE_ALL_EXCEPT);
1123 r = scalbl (LDBL_MAX, -2147483647);
1124 if (r != 0.0)
1126 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
1127 result = 1;
1129 else if (signbit (r) != 0)
1131 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1132 result = 1;
1134 else if (fetestexcept (FE_OVERFLOW))
1136 puts ("scalbl(NaN, 0) raises overflow exception");
1137 result = 1;
1140 #endif
1142 return result;