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 == 106
58 /* This has to match the mantissa of LDBL_MAX which actually does have a
59 missing bit in the middle. */
60 m
= 0x1.fffffffffffff7ffffffffffff8p
-1L;
61 # elif LDBL_MANT_DIG == 113
62 m
= 0x1.ffffffffffffffffffffffffffffp
-1L;
64 # error "Please adjust"
67 for (i
= LDBL_MAX_EXP
, x
= LDBL_MAX
; i
>= LDBL_MIN_EXP
; --i
, x
/= 2.0L)
74 printf ("mantissa incorrect: %.20La\n", r
);
80 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
87 for (i
= LDBL_MIN_EXP
, x
= LDBL_MIN
; i
>= LDBL_MIN_EXP
- LDBL_MANT_DIG
+ 1;
95 printf ("mantissa incorrect: %.20La\n", r
);
101 printf ("exponent wrong %d (%.20Lg)\n", e
, x
);
114 long double r
= frexpl (LDBL_MIN
* LDBL_EPSILON
, &e
);
118 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): mantissa wrong: %Lg\n",
122 else if (e
!= -16444)
124 printf ("frexpl (LDBL_MIN * LDBL_EPSILON, ...): exponent wrong: %d\n",
133 double x
= 0x100000001ll
+ (double) 0.5;
138 if (q
!= (double) 0x100000001ll
|| r
!= 0.5)
140 printf ("modf (%g, ...) failed\n", x
);
146 union ieee754_float v1
;
147 union ieee754_float v2
;
151 if (fpclassify (f
) != FP_NORMAL
)
153 printf ("fpclassify (FLT_MIN) failed: %d\n", fpclassify (f
));
156 f
= nextafterf (f
, FLT_MIN
/ 2.0f
);
157 if (fpclassify (f
) != FP_SUBNORMAL
)
159 printf ("fpclassify (FLT_MIN-epsilon) failed: %d\n", fpclassify (f
));
162 v2
.f
= f
= nextafterf (f
, FLT_MIN
);
163 if (fpclassify (f
) != FP_NORMAL
)
165 printf ("fpclassify (FLT_MIN-epsilon+epsilon) failed: %d\n",
170 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
172 printf ("FLT_MIN: mantissa differs: %8x vs %8x\n",
173 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
176 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
178 printf ("FLT_MIN: exponent differs: %4x vs %4x\n",
179 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
182 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
184 printf ("FLT_MIN: negative differs: %d vs %d\n",
185 v1
.ieee
.negative
, v2
.ieee
.negative
);
190 if (fpclassify (f
) != FP_NORMAL
)
192 printf ("fpclassify (-FLT_MIN) failed: %d\n", fpclassify (f
));
195 f
= nextafterf (f
, -FLT_MIN
/ 2.0f
);
196 if (fpclassify (f
) != FP_SUBNORMAL
)
198 printf ("fpclassify (-FLT_MIN-epsilon) failed: %d\n", fpclassify (f
));
201 v2
.f
= f
= nextafterf (f
, -FLT_MIN
);
202 if (fpclassify (f
) != FP_NORMAL
)
204 printf ("fpclassify (-FLT_MIN-epsilon+epsilon) failed: %d\n",
209 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
211 printf ("-FLT_MIN: mantissa differs: %8x vs %8x\n",
212 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
215 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
217 printf ("-FLT_MIN: exponent differs: %4x vs %4x\n",
218 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
221 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
223 printf ("-FLT_MIN: negative differs: %d vs %d\n",
224 v1
.ieee
.negative
, v2
.ieee
.negative
);
229 if (fpclassify (f
) != FP_NORMAL
)
231 printf ("fpclassify (FLT_MAX) failed: %d\n", fpclassify (f
));
234 f
= nextafterf (f
, INFINITY
);
235 if (fpclassify (f
) != FP_INFINITE
)
237 printf ("fpclassify (FLT_MAX+epsilon) failed: %d\n", fpclassify (f
));
242 if (fpclassify (f
) != FP_NORMAL
)
244 printf ("fpclassify (-FLT_MAX) failed: %d\n", fpclassify (f
));
247 f
= nextafterf (f
, -INFINITY
);
248 if (fpclassify (f
) != FP_INFINITE
)
250 printf ("fpclassify (-FLT_MAX-epsilon) failed: %d\n", fpclassify (f
));
255 f
= nextafterf (f
, 0.0);
256 v2
.f
= f
= nextafterf (f
, 1.0);
258 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
260 printf ("0.0625f down: mantissa differs: %8x vs %8x\n",
261 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
264 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
266 printf ("0.0625f down: exponent differs: %4x vs %4x\n",
267 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
270 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
272 printf ("0.0625f down: negative differs: %d vs %d\n",
273 v1
.ieee
.negative
, v2
.ieee
.negative
);
278 f
= nextafterf (f
, 1.0);
279 v2
.f
= f
= nextafterf (f
, 0.0);
281 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
283 printf ("0.0625f up: mantissa differs: %8x vs %8x\n",
284 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
287 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
289 printf ("0.0625f up: exponent differs: %4x vs %4x\n",
290 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
293 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
295 printf ("0.0625f up: negative differs: %d vs %d\n",
296 v1
.ieee
.negative
, v2
.ieee
.negative
);
301 f
= nextafterf (f
, 0.0);
302 v2
.f
= f
= nextafterf (f
, -1.0);
304 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
306 printf ("-0.0625f up: mantissa differs: %8x vs %8x\n",
307 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
310 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
312 printf ("-0.0625f up: exponent differs: %4x vs %4x\n",
313 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
316 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
318 printf ("-0.0625f up: negative differs: %d vs %d\n",
319 v1
.ieee
.negative
, v2
.ieee
.negative
);
324 f
= nextafterf (f
, -1.0);
325 v2
.f
= f
= nextafterf (f
, 0.0);
327 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
329 printf ("-0.0625f down: mantissa differs: %8x vs %8x\n",
330 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
333 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
335 printf ("-0.0625f down: exponent differs: %4x vs %4x\n",
336 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
339 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
341 printf ("-0.0625f down: negative differs: %d vs %d\n",
342 v1
.ieee
.negative
, v2
.ieee
.negative
);
347 f
= nextafterf (f
, 1.0);
348 v2
.f
= nextafterf (f
, -1.0);
350 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
352 printf ("0.0f up: mantissa differs: %8x vs %8x\n",
353 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
356 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
358 printf ("0.0f up: exponent differs: %4x vs %4x\n",
359 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
362 if (0 != v2
.ieee
.negative
)
364 printf ("0.0f up: negative differs: 0 vs %d\n",
370 f
= nextafterf (f
, -1.0);
371 v2
.f
= nextafterf (f
, 1.0);
373 if (v1
.ieee
.mantissa
!= v2
.ieee
.mantissa
)
375 printf ("0.0f down: mantissa differs: %8x vs %8x\n",
376 v1
.ieee
.mantissa
, v2
.ieee
.mantissa
);
379 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
381 printf ("0.0f down: exponent differs: %4x vs %4x\n",
382 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
385 if (1 != v2
.ieee
.negative
)
387 printf ("0.0f down: negative differs: 1 vs %d\n",
392 if (nextafterf (0.0f
, INFINITY
) != nextafterf (0.0f
, 1.0f
)
393 || nextafterf (-0.0f
, INFINITY
) != nextafterf (-0.0f
, 1.0f
)
394 || nextafterf (0.0f
, -INFINITY
) != nextafterf (0.0f
, -1.0f
)
395 || nextafterf (-0.0f
, -INFINITY
) != nextafterf (-0.0f
, -1.0f
))
397 printf ("nextafterf (+-0, +-Inf) != nextafterf (+-0, +-1)\n");
401 if (nexttowardf (0.0f
, INFINITY
) != nexttowardf (0.0f
, 1.0f
)
402 || nexttowardf (-0.0f
, INFINITY
) != nexttowardf (-0.0f
, 1.0f
)
403 || nexttowardf (0.0f
, -INFINITY
) != nexttowardf (0.0f
, -1.0f
)
404 || nexttowardf (-0.0f
, -INFINITY
) != nexttowardf (-0.0f
, -1.0f
))
406 printf ("nexttowardf (+-0, +-Inf) != nexttowardf (+-0, +-1)\n");
412 union ieee754_double v1
;
413 union ieee754_double v2
;
417 if (fpclassify (d
) != FP_NORMAL
)
419 printf ("fpclassify (DBL_MIN) failed: %d\n", fpclassify (d
));
422 d
= nextafter (d
, DBL_MIN
/ 2.0);
423 if (fpclassify (d
) != FP_SUBNORMAL
)
425 printf ("fpclassify (DBL_MIN-epsilon) failed: %d\n", fpclassify (d
));
428 v2
.d
= d
= nextafter (d
, DBL_MIN
);
429 if (fpclassify (d
) != FP_NORMAL
)
431 printf ("fpclassify (DBL_MIN-epsilon+epsilon) failed: %d\n",
436 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
438 printf ("DBL_MIN: mantissa0 differs: %8x vs %8x\n",
439 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
442 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
444 printf ("DBL_MIN: mantissa1 differs: %8x vs %8x\n",
445 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
448 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
450 printf ("DBL_MIN: exponent differs: %4x vs %4x\n",
451 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
454 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
456 printf ("DBL_MIN: negative differs: %d vs %d\n",
457 v1
.ieee
.negative
, v2
.ieee
.negative
);
462 if (fpclassify (d
) != FP_NORMAL
)
464 printf ("fpclassify (-DBL_MIN) failed: %d\n", fpclassify (d
));
467 d
= nextafter (d
, -DBL_MIN
/ 2.0);
468 if (fpclassify (d
) != FP_SUBNORMAL
)
470 printf ("fpclassify (-DBL_MIN-epsilon) failed: %d\n", fpclassify (d
));
473 v2
.d
= d
= nextafter (d
, -DBL_MIN
);
474 if (fpclassify (d
) != FP_NORMAL
)
476 printf ("fpclassify (-DBL_MIN-epsilon+epsilon) failed: %d\n",
481 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
483 printf ("-DBL_MIN: mantissa0 differs: %8x vs %8x\n",
484 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
487 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
489 printf ("-DBL_MIN: mantissa1 differs: %8x vs %8x\n",
490 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
493 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
495 printf ("-DBL_MIN: exponent differs: %4x vs %4x\n",
496 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
499 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
501 printf ("-DBL_MIN: negative differs: %d vs %d\n",
502 v1
.ieee
.negative
, v2
.ieee
.negative
);
507 if (fpclassify (d
) != FP_NORMAL
)
509 printf ("fpclassify (DBL_MAX) failed: %d\n", fpclassify (d
));
512 d
= nextafter (d
, INFINITY
);
513 if (fpclassify (d
) != FP_INFINITE
)
515 printf ("fpclassify (DBL_MAX+epsilon) failed: %d\n", fpclassify (d
));
520 if (fpclassify (d
) != FP_NORMAL
)
522 printf ("fpclassify (-DBL_MAX) failed: %d\n", fpclassify (d
));
525 d
= nextafter (d
, -INFINITY
);
526 if (fpclassify (d
) != FP_INFINITE
)
528 printf ("fpclassify (-DBL_MAX-epsilon) failed: %d\n", fpclassify (d
));
533 d
= nextafter (d
, 0.0);
534 v2
.d
= d
= nextafter (d
, 1.0);
536 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
538 printf ("0.0625 down: mantissa0 differs: %8x vs %8x\n",
539 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
542 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
544 printf ("0.0625 down: mantissa1 differs: %8x vs %8x\n",
545 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
548 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
550 printf ("0.0625 down: exponent differs: %4x vs %4x\n",
551 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
554 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
556 printf ("0.0625 down: negative differs: %d vs %d\n",
557 v1
.ieee
.negative
, v2
.ieee
.negative
);
562 d
= nextafter (d
, 1.0);
563 v2
.d
= d
= nextafter (d
, 0.0);
565 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
567 printf ("0.0625 up: mantissa0 differs: %8x vs %8x\n",
568 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
571 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
573 printf ("0.0625 up: mantissa1 differs: %8x vs %8x\n",
574 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
577 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
579 printf ("0.0625 up: exponent differs: %4x vs %4x\n",
580 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
583 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
585 printf ("0.0625 up: negative differs: %d vs %d\n",
586 v1
.ieee
.negative
, v2
.ieee
.negative
);
591 d
= nextafter (d
, 0.0);
592 v2
.d
= d
= nextafter (d
, -1.0);
594 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
596 printf ("-0.0625 up: mantissa0 differs: %8x vs %8x\n",
597 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
600 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
602 printf ("-0.0625 up: mantissa1 differs: %8x vs %8x\n",
603 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
606 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
608 printf ("-0.0625 up: exponent differs: %4x vs %4x\n",
609 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
612 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
614 printf ("-0.0625 up: negative differs: %d vs %d\n",
615 v1
.ieee
.negative
, v2
.ieee
.negative
);
620 d
= nextafter (d
, -1.0);
621 v2
.d
= d
= nextafter (d
, 0.0);
623 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
625 printf ("-0.0625 down: mantissa0 differs: %8x vs %8x\n",
626 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
629 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
631 printf ("-0.0625 down: mantissa1 differs: %8x vs %8x\n",
632 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
635 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
637 printf ("-0.0625 down: exponent differs: %4x vs %4x\n",
638 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
641 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
643 printf ("-0.0625 down: negative differs: %d vs %d\n",
644 v1
.ieee
.negative
, v2
.ieee
.negative
);
649 d
= nextafter (d
, 1.0);
650 v2
.d
= nextafter (d
, -1.0);
652 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
654 printf ("0.0 up: mantissa0 differs: %8x vs %8x\n",
655 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
658 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
660 printf ("0.0 up: mantissa1 differs: %8x vs %8x\n",
661 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
664 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
666 printf ("0.0 up: exponent differs: %4x vs %4x\n",
667 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
670 if (0 != v2
.ieee
.negative
)
672 printf ("0.0 up: negative differs: 0 vs %d\n",
678 d
= nextafter (d
, -1.0);
679 v2
.d
= nextafter (d
, 1.0);
681 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
683 printf ("0.0 down: mantissa0 differs: %8x vs %8x\n",
684 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
687 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
689 printf ("0.0 down: mantissa1 differs: %8x vs %8x\n",
690 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
693 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
695 printf ("0.0 down: exponent differs: %4x vs %4x\n",
696 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
699 if (1 != v2
.ieee
.negative
)
701 printf ("0.0 down: negative differs: 1 vs %d\n",
706 if (nextafter (0.0, INFINITY
) != nextafter (0.0, 1.0)
707 || nextafter (-0.0, INFINITY
) != nextafter (-0.0, 1.0)
708 || nextafter (0.0, -INFINITY
) != nextafter (0.0, -1.0)
709 || nextafter (-0.0, -INFINITY
) != nextafter (-0.0, -1.0))
711 printf ("nextafter (+-0, +-Inf) != nextafter (+-0, +-1)\n");
715 if (nexttoward (0.0, INFINITY
) != nexttoward (0.0, 1.0)
716 || nexttoward (-0.0, INFINITY
) != nexttoward (-0.0, 1.0)
717 || nexttoward (0.0, -INFINITY
) != nexttoward (0.0, -1.0)
718 || nexttoward (-0.0, -INFINITY
) != nexttoward (-0.0, -1.0))
720 printf ("nexttoward (+-0, +-Inf) != nexttoward (+-0, +-1)\n");
725 #ifndef NO_LONG_DOUBLE
727 union ieee854_long_double v1
;
728 union ieee854_long_double v2
;
731 v1
.d
= ld
= LDBL_MIN
;
732 if (fpclassify (ld
) != FP_NORMAL
)
734 printf ("fpclassify (LDBL_MIN) failed: %d\n", fpclassify (ld
));
737 ld
= nextafterl (ld
, LDBL_MIN
/ 2.0);
738 if (fpclassify (ld
) != FP_SUBNORMAL
)
740 printf ("fpclassify (LDBL_MIN-epsilon) failed: %d (%La)\n",
741 fpclassify (ld
), ld
);
744 v2
.d
= ld
= nextafterl (ld
, LDBL_MIN
);
745 if (fpclassify (ld
) != FP_NORMAL
)
747 printf ("fpclassify (LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
748 fpclassify (ld
), ld
);
752 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
754 printf ("LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
755 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
758 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
760 printf ("LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
761 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
764 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
766 printf ("LDBL_MIN: exponent differs: %4x vs %4x\n",
767 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
770 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
772 printf ("LDBL_MIN: negative differs: %d vs %d\n",
773 v1
.ieee
.negative
, v2
.ieee
.negative
);
777 v1
.d
= ld
= -LDBL_MIN
;
778 if (fpclassify (ld
) != FP_NORMAL
)
780 printf ("fpclassify (-LDBL_MIN) failed: %d\n", fpclassify (ld
));
783 ld
= nextafterl (ld
, -LDBL_MIN
/ 2.0);
784 if (fpclassify (ld
) != FP_SUBNORMAL
)
786 printf ("fpclassify (-LDBL_MIN-epsilon) failed: %d (%La)\n",
787 fpclassify (ld
), ld
);
790 v2
.d
= ld
= nextafterl (ld
, -LDBL_MIN
);
791 if (fpclassify (ld
) != FP_NORMAL
)
793 printf ("fpclassify (-LDBL_MIN-epsilon+epsilon) failed: %d (%La)\n",
794 fpclassify (ld
), ld
);
798 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
800 printf ("-LDBL_MIN: mantissa0 differs: %8x vs %8x\n",
801 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
804 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
806 printf ("-LDBL_MIN: mantissa1 differs: %8x vs %8x\n",
807 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
810 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
812 printf ("-LDBL_MIN: exponent differs: %4x vs %4x\n",
813 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
816 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
818 printf ("-LDBL_MIN: negative differs: %d vs %d\n",
819 v1
.ieee
.negative
, v2
.ieee
.negative
);
824 if (fpclassify (ld
) != FP_NORMAL
)
826 printf ("fpclassify (LDBL_MAX) failed: %d\n", fpclassify (ld
));
829 ld
= nextafterl (ld
, INFINITY
);
830 if (fpclassify (ld
) != FP_INFINITE
)
832 printf ("fpclassify (LDBL_MAX+epsilon) failed: %d\n", fpclassify (ld
));
837 if (fpclassify (ld
) != FP_NORMAL
)
839 printf ("fpclassify (-LDBL_MAX) failed: %d\n", fpclassify (ld
));
842 ld
= nextafterl (ld
, -INFINITY
);
843 if (fpclassify (ld
) != FP_INFINITE
)
845 printf ("fpclassify (-LDBL_MAX-epsilon) failed: %d\n",
851 ld
= nextafterl (ld
, 0.0);
852 v2
.d
= ld
= nextafterl (ld
, 1.0);
854 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
856 printf ("0.0625L down: mantissa0 differs: %8x vs %8x\n",
857 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
860 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
862 printf ("0.0625L down: mantissa1 differs: %8x vs %8x\n",
863 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
866 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
868 printf ("0.0625L down: exponent differs: %4x vs %4x\n",
869 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
872 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
874 printf ("0.0625L down: negative differs: %d vs %d\n",
875 v1
.ieee
.negative
, v2
.ieee
.negative
);
880 ld
= nextafterl (ld
, 1.0);
881 v2
.d
= ld
= nextafterl (ld
, 0.0);
883 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
885 printf ("0.0625L up: mantissa0 differs: %8x vs %8x\n",
886 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
889 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
891 printf ("0.0625L up: mantissa1 differs: %8x vs %8x\n",
892 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
895 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
897 printf ("0.0625L up: exponent differs: %4x vs %4x\n",
898 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
901 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
903 printf ("0.0625L up: negative differs: %d vs %d\n",
904 v1
.ieee
.negative
, v2
.ieee
.negative
);
909 ld
= nextafterl (ld
, 0.0);
910 v2
.d
= ld
= nextafterl (ld
, -1.0);
912 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
914 printf ("-0.0625L up: mantissa0 differs: %8x vs %8x\n",
915 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
918 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
920 printf ("-0.0625L up: mantissa1 differs: %8x vs %8x\n",
921 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
924 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
926 printf ("-0.0625L up: exponent differs: %4x vs %4x\n",
927 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
930 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
932 printf ("-0.0625L up: negative differs: %d vs %d\n",
933 v1
.ieee
.negative
, v2
.ieee
.negative
);
938 ld
= nextafterl (ld
, -1.0);
939 v2
.d
= ld
= nextafterl (ld
, 0.0);
941 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
943 printf ("-0.0625L down: mantissa0 differs: %8x vs %8x\n",
944 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
947 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
949 printf ("-0.0625L down: mantissa1 differs: %8x vs %8x\n",
950 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
953 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
955 printf ("-0.0625L down: exponent differs: %4x vs %4x\n",
956 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
959 if (v1
.ieee
.negative
!= v2
.ieee
.negative
)
961 printf ("-0.0625L down: negative differs: %d vs %d\n",
962 v1
.ieee
.negative
, v2
.ieee
.negative
);
967 ld
= nextafterl (ld
, 1.0);
968 v2
.d
= nextafterl (ld
, -1.0);
970 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
972 printf ("0.0L up: mantissa0 differs: %8x vs %8x\n",
973 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
976 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
978 printf ("0.0L up: mantissa1 differs: %8x vs %8x\n",
979 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
982 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
984 printf ("0.0L up: exponent differs: %4x vs %4x\n",
985 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
988 if (0 != v2
.ieee
.negative
)
990 printf ("0.0L up: negative differs: 0 vs %d\n",
996 ld
= nextafterl (ld
, -1.0);
997 v2
.d
= nextafterl (ld
, 1.0);
999 if (v1
.ieee
.mantissa0
!= v2
.ieee
.mantissa0
)
1001 printf ("0.0L down: mantissa0 differs: %8x vs %8x\n",
1002 v1
.ieee
.mantissa0
, v2
.ieee
.mantissa0
);
1005 if (v1
.ieee
.mantissa1
!= v2
.ieee
.mantissa1
)
1007 printf ("0.0L down: mantissa1 differs: %8x vs %8x\n",
1008 v1
.ieee
.mantissa1
, v2
.ieee
.mantissa1
);
1011 if (v1
.ieee
.exponent
!= v2
.ieee
.exponent
)
1013 printf ("0.0L down: exponent differs: %4x vs %4x\n",
1014 v1
.ieee
.exponent
, v2
.ieee
.exponent
);
1017 if (1 != v2
.ieee
.negative
)
1019 printf ("0.0L down: negative differs: 1 vs %d\n",
1024 if (nextafterl (0.0, INFINITY
) != nextafterl (0.0, 1.0)
1025 || nextafterl (-0.0, INFINITY
) != nextafterl (-0.0, 1.0)
1026 || nextafterl (0.0, -INFINITY
) != nextafterl (0.0, -1.0)
1027 || nextafterl (-0.0, -INFINITY
) != nextafterl (-0.0, -1.0))
1029 printf ("nextafterl (+-0, +-Inf) != nextafterl (+-0, +-1)\n");
1033 if (nexttowardl (0.0L, INFINITY
) != nexttowardl (0.0L, 1.0L)
1034 || nexttowardl (-0.0L, INFINITY
) != nexttowardl (-0.0L, 1.0L)
1035 || nexttowardl (0.0L, -INFINITY
) != nexttowardl (0.0L, -1.0L)
1036 || nexttowardl (-0.0L, -INFINITY
) != nexttowardl (-0.0L, -1.0L))
1038 printf ("nexttowardl (+-0, +-Inf) != nexttowardl (+-0, +-1)\n");
1044 if (! isnormal (FLT_MIN
))
1046 puts ("isnormal (FLT_MIN) failed");
1049 if (! isnormal (DBL_MIN
))
1051 puts ("isnormal (DBL_MIN) failed");
1054 #ifndef NO_LONG_DOUBLE
1055 if (! isnormal (LDBL_MIN
))
1057 puts ("isnormal (LDBL_MIN) failed");
1063 /* This is a test for the strange long doubles in x86 FPUs. */
1070 { .b
= { 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0 } };
1072 if (fpclassify (u
.d
) != FP_NORMAL
)
1074 printf ("fpclassify (0x00008000000000000000) failed: %d (%Lg)\n",
1075 fpclassify (u
.d
), u
.d
);
1080 /* Special NaNs in x86 long double. Test for scalbl. */
1087 { .b
= { 0, 1, 0, 0, 0, 0, 0, 0xc0, 0xff, 0x7f } };
1090 r
= scalbl (u
.d
, 0.0);
1093 puts ("scalbl(NaN, 0) does not return NaN");
1096 else if (memcmp (&r
, &u
.d
, sizeof (double)) != 0)
1098 puts ("scalbl(NaN, 0) does not return the same NaN");
1104 #ifndef NO_LONG_DOUBLE
1108 feclearexcept (FE_ALL_EXCEPT
);
1109 r
= scalbl (LDBL_MIN
, 2147483647);
1112 puts ("scalbl (LDBL_MIN, 2147483647) does not return Inf");
1115 else if (signbit (r
) != 0)
1117 puts ("scalbl (LDBL_MIN, 2147483647) returns -Inf");
1120 else if (fetestexcept (FE_UNDERFLOW
))
1122 puts ("scalbl(NaN, 0) raises underflow exception");
1126 feclearexcept (FE_ALL_EXCEPT
);
1127 r
= scalbl (LDBL_MAX
, -2147483647);
1130 puts ("scalbl (LDBL_MAX, -2147483647) does not return 0");
1133 else if (signbit (r
) != 0)
1135 puts ("scalbl (LDBL_MAX, -2147483647) returns -Inf");
1138 else if (fetestexcept (FE_OVERFLOW
))
1140 puts ("scalbl(NaN, 0) raises overflow exception");