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
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
);
47 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 96
55 # if LDBL_MANT_DIG == 64
56 m
= 0xf.fffffffffffffffp
-4L;
57 # elif LDBL_MANT_DIG == 113
58 m
= 0x1.ffffffffffffffffffffffffffffp
-1L;
60 # error "Please adjust"
63 for (i
= LDBL_MAX_EXP
, x
= LDBL_MAX
; i
>= LDBL_MIN_EXP
; --i
, x
/= 2.0L)
70 printf ("mantissa incorrect: %.20La\n", r
);
76 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
83 for (i
= LDBL_MIN_EXP
, x
= LDBL_MIN
; i
>= LDBL_MIN_EXP
- LDBL_MANT_DIG
+ 1;
91 printf ("mantissa incorrect: %.20La\n", r
);
97 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
110 long double r
= frexpl (LDBL_MIN
* LDBL_EPSILON
, &e
);
114 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
118 else if (e
!= -16444)
120 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
129 double x
= 0x100000001ll
+ (double) 0.5;
134 if (q
!= (double) 0x100000001ll
|| r
!= 0.5)
136 printf ("modf (%g, ...) failed\n", x
);
142 union ieee754_float v1
;
143 union ieee754_float v2
;
147 if (fpclassify (f
) != FP_NORMAL
)
149 printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f
));
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
));
158 v2
.f
= f
= nextafterf (f
, FLT_MIN
);
159 if (fpclassify (f
) != FP_NORMAL
)
161 printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
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
);
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
);
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
);
186 if (fpclassify (f
) != FP_NORMAL
)
188 printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f
));
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
));
197 v2
.f
= f
= nextafterf (f
, -FLT_MIN
);
198 if (fpclassify (f
) != FP_NORMAL
)
200 printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
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
);
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
);
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
);
225 if (fpclassify (f
) != FP_NORMAL
)
227 printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f
));
230 f
= nextafterf (f
, INFINITY
);
231 if (fpclassify (f
) != FP_INFINITE
)
233 printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f
));
238 if (fpclassify (f
) != FP_NORMAL
)
240 printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f
));
243 f
= nextafterf (f
, -INFINITY
);
244 if (fpclassify (f
) != FP_INFINITE
)
246 printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f
));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
358 if (0 != v2
.ieee
.negative
)
360 printf ("0.0f up: negative differs: 0 vs %d\n",
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
);
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
);
381 if (1 != v2
.ieee
.negative
)
383 printf ("0.0f down: negative differs: 1 vs %d\n",
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");
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");
408 union ieee754_double v1
;
409 union ieee754_double v2
;
413 if (fpclassify (d
) != FP_NORMAL
)
415 printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d
));
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
));
424 v2
.d
= d
= nextafter (d
, DBL_MIN
);
425 if (fpclassify (d
) != FP_NORMAL
)
427 printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
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
);
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
);
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
);
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
);
458 if (fpclassify (d
) != FP_NORMAL
)
460 printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d
));
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
));
469 v2
.d
= d
= nextafter (d
, -DBL_MIN
);
470 if (fpclassify (d
) != FP_NORMAL
)
472 printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
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
);
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
);
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
);
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
);
503 if (fpclassify (d
) != FP_NORMAL
)
505 printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d
));
508 d
= nextafter (d
, INFINITY
);
509 if (fpclassify (d
) != FP_INFINITE
)
511 printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d
));
516 if (fpclassify (d
) != FP_NORMAL
)
518 printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d
));
521 d
= nextafter (d
, -INFINITY
);
522 if (fpclassify (d
) != FP_INFINITE
)
524 printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d
));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
666 if (0 != v2
.ieee
.negative
)
668 printf ("0.0 up: negative differs: 0 vs %d\n",
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
);
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
);
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
);
695 if (1 != v2
.ieee
.negative
)
697 printf ("0.0 down: negative differs: 1 vs %d\n",
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");
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");
721 #ifndef NO_LONG_DOUBLE
723 union ieee854_long_double v1
;
724 union ieee854_long_double v2
;
727 v1
.d
= ld
= LDBL_MIN
;
728 if (fpclassify (ld
) != FP_NORMAL
)
730 printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld
));
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
);
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
);
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
);
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
);
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
);
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
);
773 v1
.d
= ld
= -LDBL_MIN
;
774 if (fpclassify (ld
) != FP_NORMAL
)
776 printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld
));
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
);
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
);
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
);
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
);
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
);
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
);
820 if (fpclassify (ld
) != FP_NORMAL
)
822 printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld
));
825 ld
= nextafterl (ld
, INFINITY
);
826 if (fpclassify (ld
) != FP_INFINITE
)
828 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld
));
833 if (fpclassify (ld
) != FP_NORMAL
)
835 printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld
));
838 ld
= nextafterl (ld
, -INFINITY
);
839 if (fpclassify (ld
) != FP_INFINITE
)
841 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
984 if (0 != v2
.ieee
.negative
)
986 printf ("0.0L up: negative differs: 0 vs %d\n",
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
);
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
);
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
);
1013 if (1 != v2
.ieee
.negative
)
1015 printf ("0.0L down: negative differs: 1 vs %d\n",
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");
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");
1040 if (! isnormal (FLT_MIN
))
1042 puts ("isnormal (FLT_MIN) failed");
1045 if (! isnormal (DBL_MIN
))
1047 puts ("isnormal (DBL_MIN) failed");
1050 #ifndef NO_LONG_DOUBLE
1051 if (! isnormal (LDBL_MIN
))
1053 puts ("isnormal (LDBL_MIN) failed");
1059 /* This is a test for the strange long doubles in x86 FPUs. */
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
);
1076 /* Special NaNs in x86 long double. Test for scalbl. */
1083 { .b
= { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
1086 r
= scalbl (u
.d
, 0.0);
1089 puts ("scalbl(NaN, 0) does not return NaN");
1092 else if (memcmp (&r
, &u
.d
, sizeof (double)) != 0)
1094 puts ("scalbl(NaN, 0) does not return the same NaN");
1100 #ifndef NO_LONG_DOUBLE
1104 feclearexcept (FE_ALL_EXCEPT
);
1105 r
= scalbl (LDBL_MIN
, 2147483647);
1108 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
1111 else if (signbit (r
) != 0)
1113 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
1116 else if (fetestexcept (FE_UNDERFLOW
))
1118 puts ("scalbl(NaN, 0) raises underflow exception");
1122 feclearexcept (FE_ALL_EXCEPT
);
1123 r
= scalbl (LDBL_MAX
, -2147483647);
1126 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
1129 else if (signbit (r
) != 0)
1131 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1134 else if (fetestexcept (FE_OVERFLOW
))
1136 puts ("scalbl(NaN, 0) raises overflow exception");