1 /* Miscellaneous tests which don't fit anywhere else.
2 Copyright (C) 2000, 2001, 2004, 2005, 2007 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
33 #ifndef NO_LONG_DOUBLE
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 "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 #ifndef NO_LONG_DOUBLE
725 union ieee854_long_double v1
;
726 union ieee854_long_double v2
;
729 v1
.d
= ld
= LDBL_MIN
;
730 if (fpclassify (ld
) != FP_NORMAL
)
732 printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld
));
735 ld
= nextafterl (ld
, LDBL_MIN
/ 2.0);
736 if (fpclassify (ld
) != FP_SUBNORMAL
)
738 printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
739 fpclassify (ld
), ld
);
742 v2
.d
= ld
= nextafterl (ld
, LDBL_MIN
);
743 if (fpclassify (ld
) != FP_NORMAL
)
745 printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
746 fpclassify (ld
), ld
);
750 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
752 printf ("LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
753 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
756 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
758 printf ("LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
759 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
762 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
764 printf ("LDBL_MIN: exponent differs: %4x vs %4x\n",
765 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
768 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
770 printf ("LDBL_MIN: negative differs: %d vs %d\n",
771 v1
.ieee
.negative
, v2
.ieee
.negative
);
775 v1
.d
= ld
= -LDBL_MIN
;
776 if (fpclassify (ld
) != FP_NORMAL
)
778 printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld
));
781 ld
= nextafterl (ld
, -LDBL_MIN
/ 2.0);
782 if (fpclassify (ld
) != FP_SUBNORMAL
)
784 printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
785 fpclassify (ld
), ld
);
788 v2
.d
= ld
= nextafterl (ld
, -LDBL_MIN
);
789 if (fpclassify (ld
) != FP_NORMAL
)
791 printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
792 fpclassify (ld
), ld
);
796 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
798 printf ("-LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
799 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
802 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
804 printf ("-LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
805 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
808 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
810 printf ("-LDBL_MIN: exponent differs: %4x vs %4x\n",
811 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
814 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
816 printf ("-LDBL_MIN: negative differs: %d vs %d\n",
817 v1
.ieee
.negative
, v2
.ieee
.negative
);
822 if (fpclassify (ld
) != FP_NORMAL
)
824 printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld
));
827 ld
= nextafterl (ld
, INFINITY
);
828 if (fpclassify (ld
) != FP_INFINITE
)
830 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld
));
835 if (fpclassify (ld
) != FP_NORMAL
)
837 printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld
));
840 ld
= nextafterl (ld
, -INFINITY
);
841 if (fpclassify (ld
) != FP_INFINITE
)
843 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
849 ld
= nextafterl (ld
, 0.0);
850 v2
.d
= ld
= nextafterl (ld
, 1.0);
852 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
854 printf ("0.0625L down: mantissa0 differs: %8x vs %8x\n",
855 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
858 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
860 printf ("0.0625L down: mantissa1 differs: %8x vs %8x\n",
861 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
864 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
866 printf ("0.0625L down: exponent differs: %4x vs %4x\n",
867 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
870 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
872 printf ("0.0625L down: negative differs: %d vs %d\n",
873 v1
.ieee
.negative
, v2
.ieee
.negative
);
878 ld
= nextafterl (ld
, 1.0);
879 v2
.d
= ld
= nextafterl (ld
, 0.0);
881 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
883 printf ("0.0625L up: mantissa0 differs: %8x vs %8x\n",
884 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
887 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
889 printf ("0.0625L up: mantissa1 differs: %8x vs %8x\n",
890 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
893 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
895 printf ("0.0625L up: exponent differs: %4x vs %4x\n",
896 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
899 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
901 printf ("0.0625L up: negative differs: %d vs %d\n",
902 v1
.ieee
.negative
, v2
.ieee
.negative
);
907 ld
= nextafterl (ld
, 0.0);
908 v2
.d
= ld
= nextafterl (ld
, -1.0);
910 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
912 printf ("-0.0625L up: mantissa0 differs: %8x vs %8x\n",
913 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
916 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
918 printf ("-0.0625L up: mantissa1 differs: %8x vs %8x\n",
919 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
922 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
924 printf ("-0.0625L up: exponent differs: %4x vs %4x\n",
925 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
928 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
930 printf ("-0.0625L up: negative differs: %d vs %d\n",
931 v1
.ieee
.negative
, v2
.ieee
.negative
);
936 ld
= nextafterl (ld
, -1.0);
937 v2
.d
= ld
= nextafterl (ld
, 0.0);
939 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
941 printf ("-0.0625L down: mantissa0 differs: %8x vs %8x\n",
942 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
945 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
947 printf ("-0.0625L down: mantissa1 differs: %8x vs %8x\n",
948 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
951 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
953 printf ("-0.0625L down: exponent differs: %4x vs %4x\n",
954 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
957 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
959 printf ("-0.0625L down: negative differs: %d vs %d\n",
960 v1
.ieee
.negative
, v2
.ieee
.negative
);
965 ld
= nextafterl (ld
, 1.0);
966 v2
.d
= nextafterl (ld
, -1.0);
968 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
970 printf ("0.0L up: mantissa0 differs: %8x vs %8x\n",
971 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
974 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
976 printf ("0.0L up: mantissa1 differs: %8x vs %8x\n",
977 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
980 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
982 printf ("0.0L up: exponent differs: %4x vs %4x\n",
983 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
986 if (0 != v2
.ieee
.negative
)
988 printf ("0.0L up: negative differs: 0 vs %d\n",
994 ld
= nextafterl (ld
, -1.0);
995 v2
.d
= nextafterl (ld
, 1.0);
997 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
999 printf ("0.0L down: mantissa0 differs: %8x vs %8x\n",
1000 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
1003 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
1005 printf ("0.0L down: mantissa1 differs: %8x vs %8x\n",
1006 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
1009 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
1011 printf ("0.0L down: exponent differs: %4x vs %4x\n",
1012 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
1015 if (1 != v2
.ieee
.negative
)
1017 printf ("0.0L down: negative differs: 1 vs %d\n",
1022 if (nextafterl (0.0, INFINITY
) != nextafterl (0.0, 1.0)
1023 || nextafterl (-0.0, INFINITY
) != nextafterl (-0.0, 1.0)
1024 || nextafterl (0.0, -INFINITY
) != nextafterl (0.0, -1.0)
1025 || nextafterl (-0.0, -INFINITY
) != nextafterl (-0.0, -1.0))
1027 printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
1031 if (nexttowardl (0.0L, INFINITY
) != nexttowardl (0.0L, 1.0L)
1032 || nexttowardl (-0.0L, INFINITY
) != nexttowardl (-0.0L, 1.0L)
1033 || nexttowardl (0.0L, -INFINITY
) != nexttowardl (0.0L, -1.0L)
1034 || nexttowardl (-0.0L, -INFINITY
) != nexttowardl (-0.0L, -1.0L))
1036 printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
1042 if (! isnormal (FLT_MIN
))
1044 puts ("isnormal (FLT_MIN) failed");
1047 if (! isnormal (DBL_MIN
))
1049 puts ("isnormal (DBL_MIN) failed");
1052 #ifndef NO_LONG_DOUBLE
1053 if (! isnormal (LDBL_MIN
))
1055 puts ("isnormal (LDBL_MIN) failed");
1061 /* This is a test for the strange long doubles in x86 FPUs. */
1068 { .b
= { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
1070 if (fpclassify (u
.d
) != FP_NORMAL
)
1072 printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
1073 fpclassify (u
.d
), u
.d
);
1078 /* Special NaNs in x86 long double. Test for scalbl. */
1085 { .b
= { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
1088 r
= scalbl (u
.d
, 0.0);
1091 puts ("scalbl(NaN, 0) does not return NaN");
1094 else if (memcmp (&r
, &u
.d
, sizeof (double)) != 0)
1096 puts ("scalbl(NaN, 0) does not return the same NaN");
1102 #ifndef NO_LONG_DOUBLE
1106 feclearexcept (FE_ALL_EXCEPT
);
1107 r
= scalbl (LDBL_MIN
, 2147483647);
1110 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
1113 else if (signbit (r
) != 0)
1115 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
1118 else if (fetestexcept (FE_UNDERFLOW
))
1120 puts ("scalbl(NaN, 0) raises underflow exception");
1124 feclearexcept (FE_ALL_EXCEPT
);
1125 r
= scalbl (LDBL_MAX
, -2147483647);
1128 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
1131 else if (signbit (r
) != 0)
1133 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1136 else if (fetestexcept (FE_OVERFLOW
))
1138 puts ("scalbl(NaN, 0) raises overflow exception");
1144 /* The tests here are very similar to tests earlier in this file,
1145 the important difference is just that there are no intervening
1146 union variables that cause some GCC versions to hide possible
1147 bugs in nextafter* implementation. */
1148 if (nextafterf (nextafterf (FLT_MIN
, FLT_MIN
/ 2.0), FLT_MIN
) != FLT_MIN
)
1150 puts ("nextafterf FLT_MIN test failed");
1153 if (nextafterf (nextafterf (-FLT_MIN
, -FLT_MIN
/ 2.0), -FLT_MIN
)
1156 puts ("nextafterf -FLT_MIN test failed");
1159 if (nextafter (nextafter (DBL_MIN
, DBL_MIN
/ 2.0), DBL_MIN
) != DBL_MIN
)
1161 puts ("nextafter DBL_MIN test failed");
1164 if (nextafter (nextafter (-DBL_MIN
, -DBL_MIN
/ 2.0), -DBL_MIN
) != -DBL_MIN
)
1166 puts ("nextafter -DBL_MIN test failed");
1169 #ifndef NO_LONG_DOUBLE
1170 if (nextafterl (nextafterl (LDBL_MIN
, LDBL_MIN
/ 2.0), LDBL_MIN
)
1173 puts ("nextafterl LDBL_MIN test failed");
1176 if (nextafterl (nextafterl (-LDBL_MIN
, -LDBL_MIN
/ 2.0), -LDBL_MIN
)
1179 puts ("nextafterl -LDBL_MIN test failed");
1184 volatile float f1
= FLT_MAX
;
1185 volatile float f2
= FLT_MAX
/ 2;
1188 feclearexcept (FE_ALL_EXCEPT
);
1190 int fe
= fetestexcept (FE_ALL_EXCEPT
);
1191 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1193 printf ("float overflow test failed: %x\n", fe
);
1197 volatile double d1
= DBL_MAX
;
1198 volatile double d2
= DBL_MAX
/ 2;
1201 feclearexcept (FE_ALL_EXCEPT
);
1203 fe
= fetestexcept (FE_ALL_EXCEPT
);
1204 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1206 printf ("double overflow test failed: %x\n", fe
);
1210 #ifndef NO_LONG_DOUBLE
1211 volatile long double ld1
= LDBL_MAX
;
1212 volatile long double ld2
= LDBL_MAX
/ 2;
1215 feclearexcept (FE_ALL_EXCEPT
);
1217 fe
= fetestexcept (FE_ALL_EXCEPT
);
1218 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1220 printf ("long double overflow test failed: %x\n", fe
);
1225 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
1226 volatile long double ld3
= 0x1.0000000000010000000100000001p
+1;
1227 volatile long double ld4
= 0x1.0000000000000000000000000001p
+1;
1231 if (ld3
!= 0x1.0p
-47)
1233 printf ("long double subtraction test failed %.28La\n", ld3
);
1238 /* Skip testing IBM long double format, for 2 reasons:
1239 1) it only supports FE_TONEAREST
1240 2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
1241 nextafter (0.0, 1.0) / 16.0L will be 0.0L. */
1242 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG >= DBL_MANT_DIG + 4 \
1243 && LDBL_MANT_DIG != 106
1244 int oldmode
= fegetround ();
1246 for (j
= 0; j
< 4; j
++)
1256 mode
= FE_TONEAREST
;
1274 #ifdef FE_TOWARDZERO
1276 mode
= FE_TOWARDZERO
;
1284 volatile long double ld5
= nextafter (0.0, 1.0) / 16.0L;
1287 for (i
= 0; i
<= 32; i
++)
1289 if (fesetround (mode
))
1291 printf ("failed to set rounding mode to %s\n", mstr
);
1297 fesetround (oldmode
);
1298 if (d5
!= ((j
== 0 && i
== 8) ? 0 : (i
+ k
) / 16)
1299 * nextafter (0.0, 1.0))
1301 printf ("%La incorrectly rounded to %s as %a\n",
1308 volatile long double ld7
= nextafterl (0.0L, 1.0L);
1311 fesetround (FE_UPWARD
);
1314 fesetround (oldmode
);
1316 if (d7
!= nextafter (0.0, 1.0))
1318 printf ("%La incorrectly rounded upward to %a\n", ld7
, d7
);