1 /* Test of isnand() substitute.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, from code by Bruno
18 Haible <bruno@clisp.org>. */
24 /* isnan must be a macro. */
26 # error missing declaration
32 #include "minus-zero.h"
42 ASSERT (!isnan (3.141f
));
43 ASSERT (!isnan (3.141e30f
));
44 ASSERT (!isnan (3.141e-30f
));
45 ASSERT (!isnan (-2.718f
));
46 ASSERT (!isnan (-2.718e30f
));
47 ASSERT (!isnan (-2.718e-30f
));
48 ASSERT (!isnan (0.0f
));
49 ASSERT (!isnan (minus_zerof
));
50 /* Infinite values. */
51 ASSERT (!isnan (Infinityf ()));
52 ASSERT (!isnan (- Infinityf ()));
54 ASSERT (isnan (NaNf ()));
57 ASSERT (isnan (SNaNf ()));
65 ASSERT (!isnan (3.141));
66 ASSERT (!isnan (3.141e30
));
67 ASSERT (!isnan (3.141e-30));
68 ASSERT (!isnan (-2.718));
69 ASSERT (!isnan (-2.718e30
));
70 ASSERT (!isnan (-2.718e-30));
71 ASSERT (!isnan (0.0));
72 ASSERT (!isnan (minus_zerod
));
73 /* Infinite values. */
74 ASSERT (!isnan (Infinityd ()));
75 ASSERT (!isnan (- Infinityd ()));
77 ASSERT (isnan (NaNd ()));
80 ASSERT (isnan (SNaNd ()));
85 test_long_double (void)
88 ASSERT (!isnan (3.141L));
89 ASSERT (!isnan (3.141e30L
));
90 ASSERT (!isnan (3.141e-30L));
91 ASSERT (!isnan (-2.718L));
92 ASSERT (!isnan (-2.718e30L
));
93 ASSERT (!isnan (-2.718e-30L));
94 ASSERT (!isnan (0.0L));
95 ASSERT (!isnan (minus_zerol
));
96 /* Infinite values. */
97 ASSERT (!isnan (Infinityl ()));
98 ASSERT (!isnan (- Infinityl ()));
100 ASSERT (isnan (NaNl ()));
102 /* Signalling NaN. */
103 ASSERT (isnan (SNaNl ()));
106 #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
108 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
109 typedef union { unsigned int word
[NWORDS
]; long double value
; }
111 /* Representation of an 80-bit 'long double' as an initializer for a sequence
112 of 'unsigned int' words. */
113 # ifdef WORDS_BIGENDIAN
114 # define LDBL80_WORDS(exponent,manthi,mantlo) \
115 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
116 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
117 (unsigned int) (mantlo) << 16 \
120 # define LDBL80_WORDS(exponent,manthi,mantlo) \
121 { mantlo, manthi, exponent }
124 static memory_long_double x
=
125 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
126 ASSERT (isnan (x
.value
));
129 /* Signalling NaN. */
130 static memory_long_double x
=
131 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
132 ASSERT (isnan (x
.value
));
134 /* isnan should return something for noncanonical values. */
136 static memory_long_double x
=
137 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
138 ASSERT (isnan (x
.value
) || !isnan (x
.value
));
140 { /* Pseudo-Infinity. */
141 static memory_long_double x
=
142 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
143 ASSERT (isnan (x
.value
) || !isnan (x
.value
));
146 static memory_long_double x
=
147 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
148 ASSERT (isnan (x
.value
) || !isnan (x
.value
));
150 { /* Unnormalized number. */
151 static memory_long_double x
=
152 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
153 ASSERT (isnan (x
.value
) || !isnan (x
.value
));
155 { /* Pseudo-Denormal. */
156 static memory_long_double x
=
157 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
158 ASSERT (isnan (x
.value
) || !isnan (x
.value
));
170 return test_exit_status
;