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, see
17 <http://www.gnu.org/licenses/>. */
32 #ifndef NO_LONG_DOUBLE
34 long double x
= 0x100000001ll
+ (long double) 0.5;
39 if (q
!= (long double) 0x100000001ll
|| r
!= 0.5)
41 printf ("modfl (%Lg, ...) failed\n", x
);
53 # if LDBL_MANT_DIG == 64
54 m
= 0xf.fffffffffffffffp
-4L;
55 # elif LDBL_MANT_DIG == 106
56 /* This has to match the mantissa of LDBL_MAX which actually does have a
57 missing bit in the middle. */
58 m
= 0x1.fffffffffffff7ffffffffffff8p
-1L;
59 # elif LDBL_MANT_DIG == 113
60 m
= 0x1.ffffffffffffffffffffffffffffp
-1L;
62 # error "Please adjust"
65 for (i
= LDBL_MAX_EXP
, x
= LDBL_MAX
; i
>= LDBL_MIN_EXP
; --i
, x
/= 2.0L)
72 printf ("mantissa incorrect: %.20La\n", r
);
78 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
85 for (i
= LDBL_MIN_EXP
, x
= LDBL_MIN
; i
>= LDBL_MIN_EXP
- LDBL_MANT_DIG
+ 1;
93 printf ("mantissa incorrect: %.20La\n", r
);
99 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
111 long double r
= frexpl (LDBL_MIN
* LDBL_EPSILON
, &e
);
115 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
119 else if (e
!= -16444)
121 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
130 double x
= 0x100000001ll
+ (double) 0.5;
135 if (q
!= (double) 0x100000001ll
|| r
!= 0.5)
137 printf ("modf (%g, ...) failed\n", x
);
143 union ieee754_float v1
;
144 union ieee754_float v2
;
148 if (fpclassify (f
) != FP_NORMAL
)
150 printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f
));
153 f
= nextafterf (f
, FLT_MIN
/ 2.0f
);
154 if (fpclassify (f
) != FP_SUBNORMAL
)
156 printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f
));
159 v2
.f
= f
= nextafterf (f
, FLT_MIN
);
160 if (fpclassify (f
) != FP_NORMAL
)
162 printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
167 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
169 printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
170 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
173 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
175 printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
176 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
179 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
181 printf ("FLT_MIN: negative differs: %d vs %d\n",
182 v1
.ieee
.negative
, v2
.ieee
.negative
);
187 if (fpclassify (f
) != FP_NORMAL
)
189 printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f
));
192 f
= nextafterf (f
, -FLT_MIN
/ 2.0f
);
193 if (fpclassify (f
) != FP_SUBNORMAL
)
195 printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f
));
198 v2
.f
= f
= nextafterf (f
, -FLT_MIN
);
199 if (fpclassify (f
) != FP_NORMAL
)
201 printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
206 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
208 printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
209 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
212 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
214 printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
215 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
218 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
220 printf ("-FLT_MIN: negative differs: %d vs %d\n",
221 v1
.ieee
.negative
, v2
.ieee
.negative
);
226 if (fpclassify (f
) != FP_NORMAL
)
228 printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f
));
231 f
= nextafterf (f
, INFINITY
);
232 if (fpclassify (f
) != FP_INFINITE
)
234 printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f
));
239 if (fpclassify (f
) != FP_NORMAL
)
241 printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f
));
244 f
= nextafterf (f
, -INFINITY
);
245 if (fpclassify (f
) != FP_INFINITE
)
247 printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f
));
252 f
= nextafterf (f
, 0.0);
253 v2
.f
= f
= nextafterf (f
, 1.0);
255 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
257 printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
258 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
261 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
263 printf ("0.0625f down: exponent differs: %4x vs %4x\n",
264 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
267 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
269 printf ("0.0625f down: negative differs: %d vs %d\n",
270 v1
.ieee
.negative
, v2
.ieee
.negative
);
275 f
= nextafterf (f
, 1.0);
276 v2
.f
= f
= nextafterf (f
, 0.0);
278 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
280 printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
281 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
284 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
286 printf ("0.0625f up: exponent differs: %4x vs %4x\n",
287 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
290 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
292 printf ("0.0625f up: negative differs: %d vs %d\n",
293 v1
.ieee
.negative
, v2
.ieee
.negative
);
298 f
= nextafterf (f
, 0.0);
299 v2
.f
= f
= nextafterf (f
, -1.0);
301 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
303 printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
304 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
307 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
309 printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
310 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
313 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
315 printf ("-0.0625f up: negative differs: %d vs %d\n",
316 v1
.ieee
.negative
, v2
.ieee
.negative
);
321 f
= nextafterf (f
, -1.0);
322 v2
.f
= f
= nextafterf (f
, 0.0);
324 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
326 printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
327 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
330 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
332 printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
333 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
336 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
338 printf ("-0.0625f down: negative differs: %d vs %d\n",
339 v1
.ieee
.negative
, v2
.ieee
.negative
);
344 f
= nextafterf (f
, 1.0);
345 v2
.f
= nextafterf (f
, -1.0);
347 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
349 printf ("0.0f up: mantissa differs: %8x vs %8x\n",
350 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
353 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
355 printf ("0.0f up: exponent differs: %4x vs %4x\n",
356 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
359 if (0 != v2
.ieee
.negative
)
361 printf ("0.0f up: negative differs: 0 vs %d\n",
367 f
= nextafterf (f
, -1.0);
368 v2
.f
= nextafterf (f
, 1.0);
370 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
372 printf ("0.0f down: mantissa differs: %8x vs %8x\n",
373 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
376 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
378 printf ("0.0f down: exponent differs: %4x vs %4x\n",
379 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
382 if (1 != v2
.ieee
.negative
)
384 printf ("0.0f down: negative differs: 1 vs %d\n",
389 if (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
)
392 || nextafterf (-0.0f
, -INFINITY
) != nextafterf (-0.0f
, -1.0f
))
394 printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
398 if (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
)
401 || nexttowardf (-0.0f
, -INFINITY
) != nexttowardf (-0.0f
, -1.0f
))
403 printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
409 union ieee754_double v1
;
410 union ieee754_double v2
;
414 if (fpclassify (d
) != FP_NORMAL
)
416 printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d
));
419 d
= nextafter (d
, DBL_MIN
/ 2.0);
420 if (fpclassify (d
) != FP_SUBNORMAL
)
422 printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d
));
425 v2
.d
= d
= nextafter (d
, DBL_MIN
);
426 if (fpclassify (d
) != FP_NORMAL
)
428 printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
433 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
435 printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
436 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
439 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
441 printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
442 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
445 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
447 printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
448 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
451 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
453 printf ("DBL_MIN: negative differs: %d vs %d\n",
454 v1
.ieee
.negative
, v2
.ieee
.negative
);
459 if (fpclassify (d
) != FP_NORMAL
)
461 printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d
));
464 d
= nextafter (d
, -DBL_MIN
/ 2.0);
465 if (fpclassify (d
) != FP_SUBNORMAL
)
467 printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d
));
470 v2
.d
= d
= nextafter (d
, -DBL_MIN
);
471 if (fpclassify (d
) != FP_NORMAL
)
473 printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
478 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
480 printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
481 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
484 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
486 printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
487 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
490 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
492 printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
493 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
496 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
498 printf ("-DBL_MIN: negative differs: %d vs %d\n",
499 v1
.ieee
.negative
, v2
.ieee
.negative
);
504 if (fpclassify (d
) != FP_NORMAL
)
506 printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d
));
509 d
= nextafter (d
, INFINITY
);
510 if (fpclassify (d
) != FP_INFINITE
)
512 printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d
));
517 if (fpclassify (d
) != FP_NORMAL
)
519 printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d
));
522 d
= nextafter (d
, -INFINITY
);
523 if (fpclassify (d
) != FP_INFINITE
)
525 printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d
));
530 d
= nextafter (d
, 0.0);
531 v2
.d
= d
= nextafter (d
, 1.0);
533 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
535 printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
536 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
539 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
541 printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
542 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
545 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
547 printf ("0.0625 down: exponent differs: %4x vs %4x\n",
548 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
551 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
553 printf ("0.0625 down: negative differs: %d vs %d\n",
554 v1
.ieee
.negative
, v2
.ieee
.negative
);
559 d
= nextafter (d
, 1.0);
560 v2
.d
= d
= nextafter (d
, 0.0);
562 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
564 printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
565 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
568 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
570 printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
571 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
574 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
576 printf ("0.0625 up: exponent differs: %4x vs %4x\n",
577 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
580 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
582 printf ("0.0625 up: negative differs: %d vs %d\n",
583 v1
.ieee
.negative
, v2
.ieee
.negative
);
588 d
= nextafter (d
, 0.0);
589 v2
.d
= d
= nextafter (d
, -1.0);
591 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
593 printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
594 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
597 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
599 printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
600 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
603 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
605 printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
606 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
609 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
611 printf ("-0.0625 up: negative differs: %d vs %d\n",
612 v1
.ieee
.negative
, v2
.ieee
.negative
);
617 d
= nextafter (d
, -1.0);
618 v2
.d
= d
= nextafter (d
, 0.0);
620 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
622 printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
623 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
626 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
628 printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
629 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
632 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
634 printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
635 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
638 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
640 printf ("-0.0625 down: negative differs: %d vs %d\n",
641 v1
.ieee
.negative
, v2
.ieee
.negative
);
646 d
= nextafter (d
, 1.0);
647 v2
.d
= nextafter (d
, -1.0);
649 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
651 printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
652 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
655 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
657 printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
658 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
661 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
663 printf ("0.0 up: exponent differs: %4x vs %4x\n",
664 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
667 if (0 != v2
.ieee
.negative
)
669 printf ("0.0 up: negative differs: 0 vs %d\n",
675 d
= nextafter (d
, -1.0);
676 v2
.d
= nextafter (d
, 1.0);
678 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
680 printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
681 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
684 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
686 printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
687 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
690 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
692 printf ("0.0 down: exponent differs: %4x vs %4x\n",
693 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
696 if (1 != v2
.ieee
.negative
)
698 printf ("0.0 down: negative differs: 1 vs %d\n",
703 if (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)
706 || nextafter (-0.0, -INFINITY
) != nextafter (-0.0, -1.0))
708 printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
712 if (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)
715 || nexttoward (-0.0, -INFINITY
) != nexttoward (-0.0, -1.0))
717 printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
722 #ifndef NO_LONG_DOUBLE
724 union ieee854_long_double v1
;
725 union ieee854_long_double v2
;
728 v1
.d
= ld
= LDBL_MIN
;
729 if (fpclassify (ld
) != FP_NORMAL
)
731 printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld
));
734 ld
= nextafterl (ld
, LDBL_MIN
/ 2.0);
735 if (fpclassify (ld
) != FP_SUBNORMAL
)
737 printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
738 fpclassify (ld
), ld
);
741 v2
.d
= ld
= nextafterl (ld
, LDBL_MIN
);
742 if (fpclassify (ld
) != FP_NORMAL
)
744 printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
745 fpclassify (ld
), ld
);
749 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
751 printf ("LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
752 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
755 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
757 printf ("LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
758 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
761 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
763 printf ("LDBL_MIN: exponent differs: %4x vs %4x\n",
764 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
767 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
769 printf ("LDBL_MIN: negative differs: %d vs %d\n",
770 v1
.ieee
.negative
, v2
.ieee
.negative
);
774 v1
.d
= ld
= -LDBL_MIN
;
775 if (fpclassify (ld
) != FP_NORMAL
)
777 printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld
));
780 ld
= nextafterl (ld
, -LDBL_MIN
/ 2.0);
781 if (fpclassify (ld
) != FP_SUBNORMAL
)
783 printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
784 fpclassify (ld
), ld
);
787 v2
.d
= ld
= nextafterl (ld
, -LDBL_MIN
);
788 if (fpclassify (ld
) != FP_NORMAL
)
790 printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
791 fpclassify (ld
), ld
);
795 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
797 printf ("-LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
798 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
801 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
803 printf ("-LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
804 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
807 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
809 printf ("-LDBL_MIN: exponent differs: %4x vs %4x\n",
810 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
813 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
815 printf ("-LDBL_MIN: negative differs: %d vs %d\n",
816 v1
.ieee
.negative
, v2
.ieee
.negative
);
821 if (fpclassify (ld
) != FP_NORMAL
)
823 printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld
));
826 ld
= nextafterl (ld
, INFINITY
);
827 if (fpclassify (ld
) != FP_INFINITE
)
829 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld
));
834 if (fpclassify (ld
) != FP_NORMAL
)
836 printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld
));
839 ld
= nextafterl (ld
, -INFINITY
);
840 if (fpclassify (ld
) != FP_INFINITE
)
842 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
848 ld
= nextafterl (ld
, 0.0);
849 v2
.d
= ld
= nextafterl (ld
, 1.0);
851 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
853 printf ("0.0625L down: mantissa0 differs: %8x vs %8x\n",
854 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
857 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
859 printf ("0.0625L down: mantissa1 differs: %8x vs %8x\n",
860 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
863 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
865 printf ("0.0625L down: exponent differs: %4x vs %4x\n",
866 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
869 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
871 printf ("0.0625L down: negative differs: %d vs %d\n",
872 v1
.ieee
.negative
, v2
.ieee
.negative
);
877 ld
= nextafterl (ld
, 1.0);
878 v2
.d
= ld
= nextafterl (ld
, 0.0);
880 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
882 printf ("0.0625L up: mantissa0 differs: %8x vs %8x\n",
883 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
886 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
888 printf ("0.0625L up: mantissa1 differs: %8x vs %8x\n",
889 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
892 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
894 printf ("0.0625L up: exponent differs: %4x vs %4x\n",
895 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
898 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
900 printf ("0.0625L up: negative differs: %d vs %d\n",
901 v1
.ieee
.negative
, v2
.ieee
.negative
);
906 ld
= nextafterl (ld
, 0.0);
907 v2
.d
= ld
= nextafterl (ld
, -1.0);
909 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
911 printf ("-0.0625L up: mantissa0 differs: %8x vs %8x\n",
912 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
915 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
917 printf ("-0.0625L up: mantissa1 differs: %8x vs %8x\n",
918 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
921 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
923 printf ("-0.0625L up: exponent differs: %4x vs %4x\n",
924 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
927 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
929 printf ("-0.0625L up: negative differs: %d vs %d\n",
930 v1
.ieee
.negative
, v2
.ieee
.negative
);
935 ld
= nextafterl (ld
, -1.0);
936 v2
.d
= ld
= nextafterl (ld
, 0.0);
938 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
940 printf ("-0.0625L down: mantissa0 differs: %8x vs %8x\n",
941 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
944 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
946 printf ("-0.0625L down: mantissa1 differs: %8x vs %8x\n",
947 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
950 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
952 printf ("-0.0625L down: exponent differs: %4x vs %4x\n",
953 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
956 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
958 printf ("-0.0625L down: negative differs: %d vs %d\n",
959 v1
.ieee
.negative
, v2
.ieee
.negative
);
964 ld
= nextafterl (ld
, 1.0);
965 v2
.d
= nextafterl (ld
, -1.0);
967 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
969 printf ("0.0L up: mantissa0 differs: %8x vs %8x\n",
970 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
973 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
975 printf ("0.0L up: mantissa1 differs: %8x vs %8x\n",
976 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
979 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
981 printf ("0.0L up: exponent differs: %4x vs %4x\n",
982 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
985 if (0 != v2
.ieee
.negative
)
987 printf ("0.0L up: negative differs: 0 vs %d\n",
993 ld
= nextafterl (ld
, -1.0);
994 v2
.d
= nextafterl (ld
, 1.0);
996 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
998 printf ("0.0L down: mantissa0 differs: %8x vs %8x\n",
999 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
1002 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
1004 printf ("0.0L down: mantissa1 differs: %8x vs %8x\n",
1005 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
1008 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
1010 printf ("0.0L down: exponent differs: %4x vs %4x\n",
1011 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
1014 if (1 != v2
.ieee
.negative
)
1016 printf ("0.0L down: negative differs: 1 vs %d\n",
1021 if (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)
1024 || nextafterl (-0.0, -INFINITY
) != nextafterl (-0.0, -1.0))
1026 printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
1030 if (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)
1033 || nexttowardl (-0.0L, -INFINITY
) != nexttowardl (-0.0L, -1.0L))
1035 printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
1041 if (! isnormal (FLT_MIN
))
1043 puts ("isnormal (FLT_MIN) failed");
1046 if (! isnormal (DBL_MIN
))
1048 puts ("isnormal (DBL_MIN) failed");
1051 #ifndef NO_LONG_DOUBLE
1052 if (! isnormal (LDBL_MIN
))
1054 puts ("isnormal (LDBL_MIN) failed");
1060 /* This is a test for the strange long doubles in x86 FPUs. */
1067 { .b
= { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
1069 if (fpclassify (u
.d
) != FP_NORMAL
)
1071 printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
1072 fpclassify (u
.d
), u
.d
);
1077 /* Special NaNs in x86 long double. Test for scalbl. */
1084 { .b
= { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
1087 r
= scalbl (u
.d
, 0.0);
1090 puts ("scalbl(NaN, 0) does not return NaN");
1093 else if (memcmp (&r
, &u
.d
, sizeof (double)) != 0)
1095 puts ("scalbl(NaN, 0) does not return the same NaN");
1101 #ifndef NO_LONG_DOUBLE
1105 feclearexcept (FE_ALL_EXCEPT
);
1106 r
= scalbl (LDBL_MIN
, 2147483647);
1109 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
1112 else if (signbit (r
) != 0)
1114 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
1117 else if (fetestexcept (FE_UNDERFLOW
))
1119 puts ("scalbl(NaN, 0) raises underflow exception");
1123 feclearexcept (FE_ALL_EXCEPT
);
1124 r
= scalbl (LDBL_MAX
, -2147483647);
1127 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
1130 else if (signbit (r
) != 0)
1132 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1135 else if (fetestexcept (FE_OVERFLOW
))
1137 puts ("scalbl(NaN, 0) raises overflow exception");
1143 /* The tests here are very similar to tests earlier in this file,
1144 the important difference is just that there are no intervening
1145 union variables that cause some GCC versions to hide possible
1146 bugs in nextafter* implementation. */
1147 if (nextafterf (nextafterf (FLT_MIN
, FLT_MIN
/ 2.0), FLT_MIN
) != FLT_MIN
)
1149 puts ("nextafterf FLT_MIN test failed");
1152 if (nextafterf (nextafterf (-FLT_MIN
, -FLT_MIN
/ 2.0), -FLT_MIN
)
1155 puts ("nextafterf -FLT_MIN test failed");
1158 if (nextafter (nextafter (DBL_MIN
, DBL_MIN
/ 2.0), DBL_MIN
) != DBL_MIN
)
1160 puts ("nextafter DBL_MIN test failed");
1163 if (nextafter (nextafter (-DBL_MIN
, -DBL_MIN
/ 2.0), -DBL_MIN
) != -DBL_MIN
)
1165 puts ("nextafter -DBL_MIN test failed");
1168 #ifndef NO_LONG_DOUBLE
1169 if (nextafterl (nextafterl (LDBL_MIN
, LDBL_MIN
/ 2.0), LDBL_MIN
)
1172 puts ("nextafterl LDBL_MIN test failed");
1175 if (nextafterl (nextafterl (-LDBL_MIN
, -LDBL_MIN
/ 2.0), -LDBL_MIN
)
1178 puts ("nextafterl -LDBL_MIN test failed");
1183 volatile float f1
= FLT_MAX
;
1184 volatile float f2
= FLT_MAX
/ 2;
1187 feclearexcept (FE_ALL_EXCEPT
);
1189 #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1190 int fe
= fetestexcept (FE_ALL_EXCEPT
);
1191 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1193 printf ("float overflow test failed: %x\n", fe
);
1198 volatile double d1
= DBL_MAX
;
1199 volatile double d2
= DBL_MAX
/ 2;
1202 feclearexcept (FE_ALL_EXCEPT
);
1204 #if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1205 fe
= fetestexcept (FE_ALL_EXCEPT
);
1206 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1208 printf ("double overflow test failed: %x\n", fe
);
1213 #ifndef NO_LONG_DOUBLE
1214 volatile long double ld1
= LDBL_MAX
;
1215 volatile long double ld2
= LDBL_MAX
/ 2;
1218 feclearexcept (FE_ALL_EXCEPT
);
1220 # if defined(FE_OVERFLOW) && defined(FE_INEXACT)
1221 fe
= fetestexcept (FE_ALL_EXCEPT
);
1222 if (fe
!= (FE_OVERFLOW
| FE_INEXACT
))
1224 printf ("long double overflow test failed: %x\n", fe
);
1230 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG == 113
1231 volatile long double ld3
= 0x1.0000000000010000000100000001p
+1;
1232 volatile long double ld4
= 0x1.0000000000000000000000000001p
+1;
1236 if (ld3
!= 0x1.0p
-47)
1238 printf ("long double subtraction test failed %.28La\n", ld3
);
1243 /* Skip testing IBM long double format, for 2 reasons:
1244 1) it only supports FE_TONEAREST
1245 2) nextafter (0.0, 1.0) == nextafterl (0.0L, 1.0L), so
1246 nextafter (0.0, 1.0) / 16.0L will be 0.0L. */
1247 #if !defined NO_LONG_DOUBLE && LDBL_MANT_DIG >= DBL_MANT_DIG + 4 \
1248 && LDBL_MANT_DIG != 106
1249 int oldmode
= fegetround ();
1251 for (j
= 0; j
< 4; j
++)
1261 mode
= FE_TONEAREST
;
1279 #ifdef FE_TOWARDZERO
1281 mode
= FE_TOWARDZERO
;
1289 volatile long double ld5
= nextafter (0.0, 1.0) / 16.0L;
1292 for (i
= 0; i
<= 32; i
++)
1294 if (fesetround (mode
))
1296 printf ("failed to set rounding mode to %s\n", mstr
);
1302 fesetround (oldmode
);
1303 if (d5
!= ((j
== 0 && i
== 8) ? 0 : (i
+ k
) / 16)
1304 * nextafter (0.0, 1.0))
1306 printf ("%La incorrectly rounded to %s as %a\n",
1313 volatile long double ld7
= nextafterl (0.0L, 1.0L);
1316 fesetround (FE_UPWARD
);
1319 fesetround (oldmode
);
1321 if (d7
!= nextafter (0.0, 1.0))
1323 printf ("%La incorrectly rounded upward to %a\n", ld7
, d7
);