| 1 |
/* Test of isnanl() substitute. |
| 2 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation, either version 3 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
/* Written by Bruno Haible <[email protected]>, 2007. */ |
| 18 |
|
| 19 |
#include <float.h> |
| 20 |
#include <limits.h> |
| 21 |
|
| 22 |
#include "minus-zero.h" |
| 23 |
#include "infinity.h" |
| 24 |
#include "nan.h" |
| 25 |
#include "snan.h" |
| 26 |
#include "macros.h" |
| 27 |
|
| 28 |
int |
| 29 |
main () |
| 30 |
{ |
| 31 |
/* Finite values. */ |
| 32 |
ASSERT (!isnanl (3.141L)); |
| 33 |
ASSERT (!isnanl (3.141e30L)); |
| 34 |
ASSERT (!isnanl (3.141e-30L)); |
| 35 |
ASSERT (!isnanl (-2.718L)); |
| 36 |
ASSERT (!isnanl (-2.718e30L)); |
| 37 |
ASSERT (!isnanl (-2.718e-30L)); |
| 38 |
ASSERT (!isnanl (0.0L)); |
| 39 |
ASSERT (!isnanl (minus_zerol)); |
| 40 |
/* Infinite values. */ |
| 41 |
ASSERT (!isnanl (Infinityl ())); |
| 42 |
ASSERT (!isnanl (- Infinityl ())); |
| 43 |
/* Quiet NaN. */ |
| 44 |
ASSERT (isnanl (NaNl ())); |
| 45 |
#if HAVE_SNANL |
| 46 |
/* Signalling NaN. */ |
| 47 |
ASSERT (isnanl (SNaNl ())); |
| 48 |
#endif |
| 49 |
|
| 50 |
#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE |
| 51 |
/* Representation of an 80-bit 'long double' as an initializer for a sequence |
| 52 |
of 'unsigned int' words. */ |
| 53 |
# ifdef WORDS_BIGENDIAN |
| 54 |
# define LDBL80_WORDS(exponent,manthi,mantlo) \ |
| 55 |
{ ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ |
| 56 |
((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \ |
| 57 |
(unsigned int) (mantlo) << 16 \ |
| 58 |
} |
| 59 |
# else |
| 60 |
# define LDBL80_WORDS(exponent,manthi,mantlo) \ |
| 61 |
{ mantlo, manthi, exponent } |
| 62 |
# endif |
| 63 |
{ /* Quiet NaN. */ |
| 64 |
static memory_long_double x = |
| 65 |
{ .word = LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; |
| 66 |
ASSERT (isnanl (x.value)); |
| 67 |
} |
| 68 |
{ |
| 69 |
/* Signalling NaN. */ |
| 70 |
static memory_long_double x = |
| 71 |
{ .word = LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; |
| 72 |
ASSERT (isnanl (x.value)); |
| 73 |
} |
| 74 |
/* isnanl should return something for noncanonical values. */ |
| 75 |
{ /* Pseudo-NaN. */ |
| 76 |
static memory_long_double x = |
| 77 |
{ .word = LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; |
| 78 |
ASSERT (isnanl (x.value) || !isnanl (x.value)); |
| 79 |
} |
| 80 |
{ /* Pseudo-Infinity. */ |
| 81 |
static memory_long_double x = |
| 82 |
{ .word = LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; |
| 83 |
ASSERT (isnanl (x.value) || !isnanl (x.value)); |
| 84 |
} |
| 85 |
{ /* Pseudo-Zero. */ |
| 86 |
static memory_long_double x = |
| 87 |
{ .word = LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; |
| 88 |
ASSERT (isnanl (x.value) || !isnanl (x.value)); |
| 89 |
} |
| 90 |
{ /* Unnormalized number. */ |
| 91 |
static memory_long_double x = |
| 92 |
{ .word = LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; |
| 93 |
ASSERT (isnanl (x.value) || !isnanl (x.value)); |
| 94 |
} |
| 95 |
{ /* Pseudo-Denormal. */ |
| 96 |
static memory_long_double x = |
| 97 |
{ .word = LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; |
| 98 |
ASSERT (isnanl (x.value) || !isnanl (x.value)); |
| 99 |
} |
| 100 |
#undef NWORDS |
| 101 |
#endif |
| 102 |
|
| 103 |
return test_exit_status; |
| 104 |
} |