1 /* Miscellaneous tests which don't fit anywhere else.
2 Copyright (C) 2000-2021 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, see
17 <https://www.gnu.org/licenses/>. */
25 #include <math-tests.h>
33 #if LDBL_MANT_DIG > DBL_MANT_DIG
35 long double x = 0x100000001ll + (long double) 0.5;
40 if (q != (long double) 0x100000001ll || r != 0.5)
42 printf ("modfl (%Lg, ...) failed\n", x);
54 # if LDBL_MANT_DIG == 64
55 m = 0xf.fffffffffffffffp-4L;
56 # elif LDBL_MANT_DIG == 106
57 /* This has to match the mantissa of LDBL_MAX which actually does have a
58 missing bit in the middle. */
59 m = 0x1.fffffffffffff7ffffffffffff8p-1L;
60 # elif LDBL_MANT_DIG == 113
61 m = 0x1.ffffffffffffffffffffffffffffp-1L;
63 # error "Unsupported LDBL_MANT_DIG, please adjust"
66 for (i = LDBL_MAX_EXP, x = LDBL_MAX; i >= LDBL_MIN_EXP; --i, x /= 2.0L)
73 printf ("mantissa incorrect: %.20La\n", r);
79 printf ("exponent wrong %d (%.20Lg)\n", e, x);
86 for (i = LDBL_MIN_EXP, x = LDBL_MIN; i >= LDBL_MIN_EXP - LDBL_MANT_DIG + 1;
94 printf ("mantissa incorrect: %.20La\n", r);
100 printf ("exponent wrong %d (%.20Lg)\n", e, x);
112 long double r = frexpl (LDBL_MIN * LDBL_EPSILON, &e);
116 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
120 else if (e != -16444)
122 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
131 double x = 0x100000001ll + (double) 0.5;
136 if (q != (double) 0x100000001ll || r != 0.5)
138 printf ("modf (%g, ...) failed\n", x);
144 union ieee754_float v1;
145 union ieee754_float v2;
149 if (fpclassify (f) != FP_NORMAL)
151 printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f));
154 f = nextafterf (f, FLT_MIN / 2.0f);
155 if (fpclassify (f) != FP_SUBNORMAL)
157 printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
160 v2.f = f = nextafterf (f, FLT_MIN);
161 if (fpclassify (f) != FP_NORMAL)
163 printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
168 if (v1.ieee.mantissa != v2.ieee.mantissa)
170 printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
171 v1.ieee.mantissa, v2.ieee.mantissa);
174 if (v1.ieee.exponent != v2.ieee.exponent)
176 printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
177 v1.ieee.exponent, v2.ieee.exponent);
180 if (v1.ieee.negative != v2.ieee.negative)
182 printf ("FLT_MIN: negative differs: %d vs %d\n",
183 v1.ieee.negative, v2.ieee.negative);
188 if (fpclassify (f) != FP_NORMAL)
190 printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f));
193 f = nextafterf (f, -FLT_MIN / 2.0f);
194 if (fpclassify (f) != FP_SUBNORMAL)
196 printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f));
199 v2.f = f = nextafterf (f, -FLT_MIN);
200 if (fpclassify (f) != FP_NORMAL)
202 printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
207 if (v1.ieee.mantissa != v2.ieee.mantissa)
209 printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
210 v1.ieee.mantissa, v2.ieee.mantissa);
213 if (v1.ieee.exponent != v2.ieee.exponent)
215 printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
216 v1.ieee.exponent, v2.ieee.exponent);
219 if (v1.ieee.negative != v2.ieee.negative)
221 printf ("-FLT_MIN: negative differs: %d vs %d\n",
222 v1.ieee.negative, v2.ieee.negative);
227 if (fpclassify (f) != FP_NORMAL)
229 printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f));
232 f = nextafterf (f, INFINITY);
233 if (fpclassify (f) != FP_INFINITE)
235 printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f));
240 if (fpclassify (f) != FP_NORMAL)
242 printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f));
245 f = nextafterf (f, -INFINITY);
246 if (fpclassify (f) != FP_INFINITE)
248 printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f));
253 f = nextafterf (f, 0.0);
254 v2.f = f = nextafterf (f, 1.0);
256 if (v1.ieee.mantissa != v2.ieee.mantissa)
258 printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
259 v1.ieee.mantissa, v2.ieee.mantissa);
262 if (v1.ieee.exponent != v2.ieee.exponent)
264 printf ("0.0625f down: exponent differs: %4x vs %4x\n",
265 v1.ieee.exponent, v2.ieee.exponent);
268 if (v1.ieee.negative != v2.ieee.negative)
270 printf ("0.0625f down: negative differs: %d vs %d\n",
271 v1.ieee.negative, v2.ieee.negative);
276 f = nextafterf (f, 1.0);
277 v2.f = f = nextafterf (f, 0.0);
279 if (v1.ieee.mantissa != v2.ieee.mantissa)
281 printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
282 v1.ieee.mantissa, v2.ieee.mantissa);
285 if (v1.ieee.exponent != v2.ieee.exponent)
287 printf ("0.0625f up: exponent differs: %4x vs %4x\n",
288 v1.ieee.exponent, v2.ieee.exponent);
291 if (v1.ieee.negative != v2.ieee.negative)
293 printf ("0.0625f up: negative differs: %d vs %d\n",
294 v1.ieee.negative, v2.ieee.negative);
299 f = nextafterf (f, 0.0);
300 v2.f = f = nextafterf (f, -1.0);
302 if (v1.ieee.mantissa != v2.ieee.mantissa)
304 printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
305 v1.ieee.mantissa, v2.ieee.mantissa);
308 if (v1.ieee.exponent != v2.ieee.exponent)
310 printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
311 v1.ieee.exponent, v2.ieee.exponent);
314 if (v1.ieee.negative != v2.ieee.negative)
316 printf ("-0.0625f up: negative differs: %d vs %d\n",
317 v1.ieee.negative, v2.ieee.negative);
322 f = nextafterf (f, -1.0);
323 v2.f = f = nextafterf (f, 0.0);
325 if (v1.ieee.mantissa != v2.ieee.mantissa)
327 printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
328 v1.ieee.mantissa, v2.ieee.mantissa);
331 if (v1.ieee.exponent != v2.ieee.exponent)
333 printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
334 v1.ieee.exponent, v2.ieee.exponent);
337 if (v1.ieee.negative != v2.ieee.negative)
339 printf ("-0.0625f down: negative differs: %d vs %d\n",
340 v1.ieee.negative, v2.ieee.negative);
345 f = nextafterf (f, 1.0);
346 v2.f = nextafterf (f, -1.0);
348 if (v1.ieee.mantissa != v2.ieee.mantissa)
350 printf ("0.0f up: mantissa differs: %8x vs %8x\n",
351 v1.ieee.mantissa, v2.ieee.mantissa);
354 if (v1.ieee.exponent != v2.ieee.exponent)
356 printf ("0.0f up: exponent differs: %4x vs %4x\n",
357 v1.ieee.exponent, v2.ieee.exponent);
360 if (0 != v2.ieee.negative)
362 printf ("0.0f up: negative differs: 0 vs %d\n",
368 f = nextafterf (f, -1.0);
369 v2.f = nextafterf (f, 1.0);
371 if (v1.ieee.mantissa != v2.ieee.mantissa)
373 printf ("0.0f down: mantissa differs: %8x vs %8x\n",
374 v1.ieee.mantissa, v2.ieee.mantissa);
377 if (v1.ieee.exponent != v2.ieee.exponent)
379 printf ("0.0f down: exponent differs: %4x vs %4x\n",
380 v1.ieee.exponent, v2.ieee.exponent);
383 if (1 != v2.ieee.negative)
385 printf ("0.0f down: negative differs: 1 vs %d\n",
390 if (nextafterf (0.0f, INFINITY) != nextafterf (0.0f, 1.0f)
391 || nextafterf (-0.0f, INFINITY) != nextafterf (-0.0f, 1.0f)
392 || nextafterf (0.0f, -INFINITY) != nextafterf (0.0f, -1.0f)
393 || nextafterf (-0.0f, -INFINITY) != nextafterf (-0.0f, -1.0f))
395 printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
399 if (nexttowardf (0.0f, INFINITY) != nexttowardf (0.0f, 1.0f)
400 || nexttowardf (-0.0f, INFINITY) != nexttowardf (-0.0f, 1.0f)
401 || nexttowardf (0.0f, -INFINITY) != nexttowardf (0.0f, -1.0f)
402 || nexttowardf (-0.0f, -INFINITY) != nexttowardf (-0.0f, -1.0f))
404 printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
410 union ieee754_double v1;
411 union ieee754_double v2;
415 if (fpclassify (d) != FP_NORMAL)
417 printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d));
420 d = nextafter (d, DBL_MIN / 2.0);
421 if (fpclassify (d) != FP_SUBNORMAL)
423 printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
426 v2.d = d = nextafter (d, DBL_MIN);
427 if (fpclassify (d) != FP_NORMAL)
429 printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
434 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
436 printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
437 v1.ieee.mantissa0, v2.ieee.mantissa0);
440 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
442 printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
443 v1.ieee.mantissa1, v2.ieee.mantissa1);
446 if (v1.ieee.exponent != v2.ieee.exponent)
448 printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
449 v1.ieee.exponent, v2.ieee.exponent);
452 if (v1.ieee.negative != v2.ieee.negative)
454 printf ("DBL_MIN: negative differs: %d vs %d\n",
455 v1.ieee.negative, v2.ieee.negative);
460 if (fpclassify (d) != FP_NORMAL)
462 printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d));
465 d = nextafter (d, -DBL_MIN / 2.0);
466 if (fpclassify (d) != FP_SUBNORMAL)
468 printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d));
471 v2.d = d = nextafter (d, -DBL_MIN);
472 if (fpclassify (d) != FP_NORMAL)
474 printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
479 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
481 printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
482 v1.ieee.mantissa0, v2.ieee.mantissa0);
485 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
487 printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
488 v1.ieee.mantissa1, v2.ieee.mantissa1);
491 if (v1.ieee.exponent != v2.ieee.exponent)
493 printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
494 v1.ieee.exponent, v2.ieee.exponent);
497 if (v1.ieee.negative != v2.ieee.negative)
499 printf ("-DBL_MIN: negative differs: %d vs %d\n",
500 v1.ieee.negative, v2.ieee.negative);
505 if (fpclassify (d) != FP_NORMAL)
507 printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d));
510 d = nextafter (d, INFINITY);
511 if (fpclassify (d) != FP_INFINITE)
513 printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d));
518 if (fpclassify (d) != FP_NORMAL)
520 printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d));
523 d = nextafter (d, -INFINITY);
524 if (fpclassify (d) != FP_INFINITE)
526 printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d));
531 d = nextafter (d, 0.0);
532 v2.d = d = nextafter (d, 1.0);
534 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
536 printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
537 v1.ieee.mantissa0, v2.ieee.mantissa0);
540 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
542 printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
543 v1.ieee.mantissa1, v2.ieee.mantissa1);
546 if (v1.ieee.exponent != v2.ieee.exponent)
548 printf ("0.0625 down: exponent differs: %4x vs %4x\n",
549 v1.ieee.exponent, v2.ieee.exponent);
552 if (v1.ieee.negative != v2.ieee.negative)
554 printf ("0.0625 down: negative differs: %d vs %d\n",
555 v1.ieee.negative, v2.ieee.negative);
560 d = nextafter (d, 1.0);
561 v2.d = d = nextafter (d, 0.0);
563 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
565 printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
566 v1.ieee.mantissa0, v2.ieee.mantissa0);
569 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
571 printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
572 v1.ieee.mantissa1, v2.ieee.mantissa1);
575 if (v1.ieee.exponent != v2.ieee.exponent)
577 printf ("0.0625 up: exponent differs: %4x vs %4x\n",
578 v1.ieee.exponent, v2.ieee.exponent);
581 if (v1.ieee.negative != v2.ieee.negative)
583 printf ("0.0625 up: negative differs: %d vs %d\n",
584 v1.ieee.negative, v2.ieee.negative);
589 d = nextafter (d, 0.0);
590 v2.d = d = nextafter (d, -1.0);
592 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
594 printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
595 v1.ieee.mantissa0, v2.ieee.mantissa0);
598 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
600 printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
601 v1.ieee.mantissa1, v2.ieee.mantissa1);
604 if (v1.ieee.exponent != v2.ieee.exponent)
606 printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
607 v1.ieee.exponent, v2.ieee.exponent);
610 if (v1.ieee.negative != v2.ieee.negative)
612 printf ("-0.0625 up: negative differs: %d vs %d\n",
613 v1.ieee.negative, v2.ieee.negative);
618 d = nextafter (d, -1.0);
619 v2.d = d = nextafter (d, 0.0);
621 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
623 printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
624 v1.ieee.mantissa0, v2.ieee.mantissa0);
627 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
629 printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
630 v1.ieee.mantissa1, v2.ieee.mantissa1);
633 if (v1.ieee.exponent != v2.ieee.exponent)
635 printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
636 v1.ieee.exponent, v2.ieee.exponent);
639 if (v1.ieee.negative != v2.ieee.negative)
641 printf ("-0.0625 down: negative differs: %d vs %d\n",
642 v1.ieee.negative, v2.ieee.negative);
647 d = nextafter (d, 1.0);
648 v2.d = nextafter (d, -1.0);
650 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
652 printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
653 v1.ieee.mantissa0, v2.ieee.mantissa0);
656 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
658 printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
659 v1.ieee.mantissa1, v2.ieee.mantissa1);
662 if (v1.ieee.exponent != v2.ieee.exponent)
664 printf ("0.0 up: exponent differs: %4x vs %4x\n",
665 v1.ieee.exponent, v2.ieee.exponent);
668 if (0 != v2.ieee.negative)
670 printf ("0.0 up: negative differs: 0 vs %d\n",
676 d = nextafter (d, -1.0);
677 v2.d = nextafter (d, 1.0);
679 if (v1.ieee.mantissa0 != v2.ieee.mantissa0)
681 printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
682 v1.ieee.mantissa0, v2.ieee.mantissa0);
685 if (v1.ieee.mantissa1 != v2.ieee.mantissa1)
687 printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
688 v1.ieee.mantissa1, v2.ieee.mantissa1);
691 if (v1.ieee.exponent != v2.ieee.exponent)
693 printf ("0.0 down: exponent differs: %4x vs %4x\n",
694 v1.ieee.exponent, v2.ieee.exponent);
697 if (1 != v2.ieee.negative)
699 printf ("0.0 down: negative differs: 1 vs %d\n",
704 if (nextafter (0.0, INFINITY) != nextafter (0.0, 1.0)
705 || nextafter (-0.0, INFINITY) != nextafter (-0.0, 1.0)
706 || nextafter (0.0, -INFINITY) != nextafter (0.0, -1.0)
707 || nextafter (-0.0, -INFINITY) != nextafter (-0.0, -1.0))
709 printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
713 if (nexttoward (0.0, INFINITY) != nexttoward (0.0, 1.0)
714 || nexttoward (-0.0, INFINITY) != nexttoward (-0.0, 1.0)
715 || nexttoward (0.0, -INFINITY) != nexttoward (0.0, -1.0)
716 || nexttoward (-0.0, -INFINITY) != nexttoward (-0.0, -1.0))
718 printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
723 #if LDBL_MANT_DIG > DBL_MANT_DIG
728 if (fpclassify (v1) != FP_NORMAL)
730 printf ("fpclassify (LDBL_MIN) failed: %d (%La)\n",
731 fpclassify (v1), v1);
734 v2 = nextafterl (v1, LDBL_MIN / 2.0);
735 if (fpclassify (v2) != FP_SUBNORMAL)
737 printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
738 fpclassify (v2), v2);
741 v2 = nextafterl (v2, LDBL_MIN);
742 if (fpclassify (v2) != FP_NORMAL)
744 printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
745 fpclassify (v2), v2);
751 printf ("LDBL_MIN-epsilon+epsilon != LDBL_MIN: %La vs %La\n", v2, v1);
756 if (fpclassify (v1) != FP_NORMAL)
758 printf ("fpclassify (-LDBL_MIN) failed: %d (%La)\n",
759 fpclassify (v1), v1);
762 v2 = nextafterl (v1, -LDBL_MIN / 2.0);
763 if (fpclassify (v2) != FP_SUBNORMAL)
765 printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
766 fpclassify (v2), v2);
769 v2 = nextafterl (v2, -LDBL_MIN);
770 if (fpclassify (v2) != FP_NORMAL)
772 printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
773 fpclassify (v2), v2);
779 printf ("-LDBL_MIN-epsilon+epsilon != -LDBL_MIN: %La vs %La\n", v2, v1);
784 if (fpclassify (v1) != FP_NORMAL)
786 printf ("fpclassify (LDBL_MAX) failed: %d (%La)\n",
787 fpclassify (v1), v1);
790 v2 = nextafterl (v1, INFINITY);
791 if (fpclassify (v2) != FP_INFINITE)
793 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d (%La)\n",
794 fpclassify (v2), v2);
799 if (fpclassify (v1) != FP_NORMAL)
801 printf ("fpclassify (-LDBL_MAX) failed: %d (%La)\n",
802 fpclassify (v1), v1);
805 v2 = nextafterl (v1, -INFINITY);
806 if (fpclassify (v2) != FP_INFINITE)
808 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d (%La)\n",
809 fpclassify (v2), v2);
814 v2 = nextafterl (v1, 0.0);
815 v2 = nextafterl (v2, 1.0);
819 printf ("0.0625L-epsilon+epsilon != 0.0625L: %La vs %La\n", v2, v1);
824 v2 = nextafterl (v1, 1.0);
825 v2 = nextafterl (v2, 0.0);
829 printf ("0.0625L+epsilon-epsilon != 0.0625L: %La vs %La\n", v2, v1);
834 v2 = nextafterl (v1, 0.0);
835 v2 = nextafterl (v2, -1.0);
839 printf ("-0.0625L+epsilon-epsilon != -0.0625L: %La vs %La\n", v2, v1);
844 v2 = nextafterl (v1, -1.0);
845 v2 = nextafterl (v2, 0.0);
849 printf ("-0.0625L-epsilon+epsilon != -0.0625L: %La vs %La\n", v2, v1);
854 v2 = nextafterl (v1, 1.0);
855 v2 = nextafterl (v2, -1.0);
859 printf ("0.0+epsilon-epsilon != 0.0L: %La vs %La\n", v2, v1);
864 printf ("0.0+epsilon-epsilon is negative\n");
869 v2 = nextafterl (v1, -1.0);
870 v2 = nextafterl (v2, 1.0);
874 printf ("0.0-epsilon+epsilon != 0.0L: %La vs %La\n", v2, v1);
879 printf ("0.0-epsilon+epsilon is positive\n");
883 if (nextafterl (0.0, INFINITY) != nextafterl (0.0, 1.0)
884 || nextafterl (-0.0, INFINITY) != nextafterl (-0.0, 1.0)
885 || nextafterl (0.0, -INFINITY) != nextafterl (0.0, -1.0)
886 || nextafterl (-0.0, -INFINITY) != nextafterl (-0.0, -1.0))
888 printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
892 if (nexttowardl (0.0L, INFINITY) != nexttowardl (0.0L, 1.0L)
893 || nexttowardl (-0.0L, INFINITY) != nexttowardl (-0.0L, 1.0L)
894 || nexttowardl (0.0L, -INFINITY) != nexttowardl (0.0L, -1.0L)
895 || nexttowardl (-0.0L, -INFINITY) != nexttowardl (-0.0L, -1.0L))
897 printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
903 if (! isnormal (FLT_MIN))
905 puts ("isnormal (FLT_MIN) failed");
908 if (! isnormal (DBL_MIN))
910 puts ("isnormal (DBL_MIN) failed");
913 #if LDBL_MANT_DIG > DBL_MANT_DIG
914 if (! isnormal (LDBL_MIN))
916 puts ("isnormal (LDBL_MIN) failed");
921 #if defined (__i386__) || defined (__x86_64__)
922 /* This is a test for the strange long doubles in x86 FPUs. */
929 { .b = { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
931 if (fpclassify (u.d) != FP_NORMAL)
933 printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
934 fpclassify (u.d), u.d);
939 /* Special qNaNs in x86 long double. Test for scalbl. */
946 { .b = { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
949 r = scalbl (u.d, 0.0);
952 puts ("scalbl (qNaN, 0) does not return NaN");
955 else if (memcmp (&r, &u.d, sizeof (double)) != 0)
957 puts ("scalbl (qNaN, 0) does not return the same NaN");
963 #if LDBL_MANT_DIG > DBL_MANT_DIG
967 feclearexcept (FE_ALL_EXCEPT);
968 r = scalbl (LDBL_MIN, 2147483647);
971 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
974 else if (signbit (r) != 0)
976 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
980 else if (fetestexcept (FE_UNDERFLOW))
982 puts ("scalbl (LDBL_MIN, 2147483647) raises underflow exception");
987 feclearexcept (FE_ALL_EXCEPT);
988 r = scalbl (LDBL_MAX, -2147483647);
991 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
994 else if (signbit (r) != 0)
996 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1000 else if (fetestexcept (FE_OVERFLOW))
1002 puts ("scalbl (LDBL_MAX, -2147483647) raises overflow exception");
1009 /* The tests here are very similar to tests earlier in this file,
1010 the important difference is just that there are no intervening
1011 union variables that cause some GCC versions to hide possible
1012 bugs in nextafter* implementation. */
1013 if (nextafterf (nextafterf (FLT_MIN, FLT_MIN / 2.0), FLT_MIN) != FLT_MIN)
1015 puts ("nextafterf FLT_MIN test failed");
1018 if (nextafterf (nextafterf (-FLT_MIN, -FLT_MIN / 2.0), -FLT_MIN)
1021 puts ("nextafterf -FLT_MIN test failed");
1024 if (nextafter (nextafter (DBL_MIN, DBL_MIN / 2.0), DBL_MIN) != DBL_MIN)
1026 puts ("nextafter DBL_MIN test failed");
1029 if (nextafter (nextafter (-DBL_MIN, -DBL_MIN / 2.0), -DBL_MIN) != -DBL_MIN)
1031 puts ("nextafter -DBL_MIN test failed");
1034 #if LDBL_MANT_DIG > DBL_MANT_DIG
1035 if (nextafterl (nextafterl (LDBL_MIN, LDBL_MIN / 2.0), LDBL_MIN)
1038 puts ("nextafterl LDBL_MIN test failed");
1041 if (nextafterl (nextafterl (-LDBL_MIN, -LDBL_MIN / 2.0), -LDBL_MIN)
1044 puts ("nextafterl -LDBL_MIN test failed");
1049 volatile float f1 = FLT_MAX;
1050 volatile float f2 = FLT_MAX / 2;
1053 feclearexcept (FE_ALL_EXCEPT);
1055 #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1056 int fe = fetestexcept (FE_ALL_EXCEPT);
1057 if (EXCEPTION_TESTS (float) && fe != (FE_OVERFLOW | FE_INEXACT))
1059 printf ("float overflow test failed: %x\n", fe);
1064 volatile double d1 = DBL_MAX;
1065 volatile double d2 = DBL_MAX / 2;
1068 feclearexcept (FE_ALL_EXCEPT);
1070 #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1071 fe = fetestexcept (FE_ALL_EXCEPT);
1072 if (EXCEPTION_TESTS (double) && fe != (FE_OVERFLOW | FE_INEXACT))
1074 printf ("double overflow test failed: %x\n", fe);
1079 #if LDBL_MANT_DIG > DBL_MANT_DIG
1080 volatile long double ld1 = LDBL_MAX;
1081 volatile long double ld2 = LDBL_MAX / 2;
1084 feclearexcept (FE_ALL_EXCEPT);
1086 # if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1087 fe = fetestexcept (FE_ALL_EXCEPT);
1088 if (EXCEPTION_TESTS (long double) && fe != (FE_OVERFLOW | FE_INEXACT))
1090 printf ("long double overflow test failed: %x\n", fe);
1095 # if LDBL_MANT_DIG == 113
1096 volatile long double ld3 = 0x1.0000000000010000000100000001p+1;
1097 volatile long double ld4 = 0x1.0000000000000000000000000001p+1;
1101 if (ld3 != 0x1.0p-47)
1103 printf ("long double subtraction test failed %.28La\n", ld3);
1108 /* Skip testing IBM long double format, for 2 reasons:
1109 1) it only supports FE_TONEAREST
1110 2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
1111 nextafter (0.0, 1.0) / 16.0L will be 0.0L. */
1112 # if LDBL_MANT_DIG >= DBL_MANT_DIG + 4 && LDBL_MANT_DIG != 106
1113 int oldmode = fegetround ();
1115 for (j = 0; j < 4; j++)
1125 mode = FE_TONEAREST;
1143 #ifdef FE_TOWARDZERO
1145 mode = FE_TOWARDZERO;
1153 volatile long double ld5 = nextafter (0.0, 1.0) / 16.0L;
1156 for (i = 0; i <= 32; i++)
1158 if (fesetround (mode))
1160 printf ("failed to set rounding mode to %s\n", mstr);
1161 if (ROUNDING_TESTS (long double, mode)
1162 && ROUNDING_TESTS (double, mode))
1165 puts ("ignoring this failure");
1170 fesetround (oldmode);
1171 if (d5 != ((j == 0 && i == 8) ? 0 : (i + k) / 16)
1172 * nextafter (0.0, 1.0))
1174 printf ("%La incorrectly rounded to %s as %a\n",
1176 if (ROUNDING_TESTS (long double, mode)
1177 && ROUNDING_TESTS (double, mode))
1180 puts ("ignoring this failure");
1186 volatile long double ld7 = nextafterl (0.0L, 1.0L);
1189 fesetround (FE_UPWARD);
1192 fesetround (oldmode);
1194 if (d7 != nextafter (0.0, 1.0))
1196 printf ("%La incorrectly rounded upward to %a\n", ld7, d7);
1197 if (ROUNDING_TESTS (long double, FE_UPWARD)
1198 && ROUNDING_TESTS (double, FE_UPWARD))
1201 puts ("ignoring this failure");
1210 #define TEST_FUNCTION do_test ()
1211 #include "../test-skeleton.c"