1 /* Test of isinf() 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, 2008, using Bruno Haible's code as a
24 /* isinf must be a macro. */
26 # error missing declaration
38 long double zerol
= 0.0L;
44 ASSERT (!isinf (0.0f
));
45 /* Subnormal values. */
46 ASSERT (!isinf (FLT_MIN
/ 2));
47 ASSERT (!isinf (-FLT_MIN
/ 2));
49 ASSERT (!isinf (3.141f
));
50 ASSERT (!isinf (3.141e30f
));
51 ASSERT (!isinf (3.141e-30f
));
52 ASSERT (!isinf (-2.718f
));
53 ASSERT (!isinf (-2.718e30f
));
54 ASSERT (!isinf (-2.718e-30f
));
55 ASSERT (!isinf (FLT_MAX
));
56 ASSERT (!isinf (-FLT_MAX
));
57 /* Infinite values. */
58 ASSERT (isinf (Infinityf ()));
59 ASSERT (isinf (- Infinityf ()));
61 ASSERT (!isinf (zerof
/ zerof
));
64 ASSERT (!isinf (SNaNf ()));
72 ASSERT (!isinf (0.0));
73 /* Subnormal values. */
74 ASSERT (!isinf (DBL_MIN
/ 2));
75 ASSERT (!isinf (-DBL_MIN
/ 2));
77 ASSERT (!isinf (3.141));
78 ASSERT (!isinf (3.141e30
));
79 ASSERT (!isinf (3.141e-30));
80 ASSERT (!isinf (-2.718));
81 ASSERT (!isinf (-2.718e30
));
82 ASSERT (!isinf (-2.718e-30));
83 ASSERT (!isinf (DBL_MAX
));
84 ASSERT (!isinf (-DBL_MAX
));
85 /* Infinite values. */
86 ASSERT (isinf (Infinityd ()));
87 ASSERT (isinf (- Infinityd ()));
89 ASSERT (!isinf (zerod
/ zerod
));
92 ASSERT (!isinf (SNaNd ()));
100 ASSERT (!isinf (0.0L));
101 /* Subnormal values. */
102 ASSERT (!isinf (LDBL_MIN
/ 2));
103 ASSERT (!isinf (-LDBL_MIN
/ 2));
105 ASSERT (!isinf (3.141L));
106 ASSERT (!isinf (3.141e30L
));
107 ASSERT (!isinf (3.141e-30L));
108 ASSERT (!isinf (-2.718L));
109 ASSERT (!isinf (-2.718e30L
));
110 ASSERT (!isinf (-2.718e-30L));
111 ASSERT (!isinf (LDBL_MAX
));
112 ASSERT (!isinf (-LDBL_MAX
));
113 /* Infinite values. */
114 ASSERT (isinf (Infinityl ()));
115 ASSERT (isinf (- Infinityl ()));
117 ASSERT (!isinf (zerol
/ zerol
));
119 /* Signalling NaN. */
120 ASSERT (!isinf (SNaNl ()));
123 #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
125 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
126 typedef union { unsigned int word
[NWORDS
]; long double value
; }
128 /* Representation of an 80-bit 'long double' as an initializer for a sequence
129 of 'unsigned int' words. */
130 # ifdef WORDS_BIGENDIAN
131 # define LDBL80_WORDS(exponent,manthi,mantlo) \
132 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
133 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
134 (unsigned int) (mantlo) << 16 \
137 # define LDBL80_WORDS(exponent,manthi,mantlo) \
138 { mantlo, manthi, exponent }
141 static memory_long_double x
=
142 { .word
= LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
143 ASSERT (!isinf (x
.value
));
146 /* Signalling NaN. */
147 static memory_long_double x
=
148 { .word
= LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
149 ASSERT (!isinf (x
.value
));
151 /* isinf should return something for noncanonical values. */
153 static memory_long_double x
=
154 { .word
= LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
155 ASSERT (isinf (x
.value
) || !isinf (x
.value
));
157 { /* Pseudo-Infinity. */
158 static memory_long_double x
=
159 { .word
= LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
160 ASSERT (isinf (x
.value
) || !isinf (x
.value
));
163 static memory_long_double x
=
164 { .word
= LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
165 ASSERT (isinf (x
.value
) || !isinf (x
.value
));
167 { /* Unnormalized number. */
168 static memory_long_double x
=
169 { .word
= LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
170 ASSERT (isinf (x
.value
) || !isinf (x
.value
));
172 { /* Pseudo-Denormal. */
173 static memory_long_double x
=
174 { .word
= LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
175 ASSERT (isinf (x
.value
) || !isinf (x
.value
));
187 return test_exit_status
;