usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-isinf.c
blob75dc6e4b3e27658237269f64292a99cb9bf5241a
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
18 template. */
20 #include <config.h>
22 #include <math.h>
24 /* isinf must be a macro. */
25 #ifndef isinf
26 # error missing declaration
27 #endif
29 #include <float.h>
30 #include <limits.h>
32 #include "infinity.h"
33 #include "snan.h"
34 #include "macros.h"
36 float zerof = 0.0f;
37 double zerod = 0.0;
38 long double zerol = 0.0L;
40 static void
41 test_isinff ()
43 /* Zero. */
44 ASSERT (!isinf (0.0f));
45 /* Subnormal values. */
46 ASSERT (!isinf (FLT_MIN / 2));
47 ASSERT (!isinf (-FLT_MIN / 2));
48 /* Finite values. */
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 ()));
60 /* Quiet NaN. */
61 ASSERT (!isinf (zerof / zerof));
62 #if HAVE_SNANF
63 /* Signalling NaN. */
64 ASSERT (!isinf (SNaNf ()));
65 #endif
68 static void
69 test_isinfd ()
71 /* Zero. */
72 ASSERT (!isinf (0.0));
73 /* Subnormal values. */
74 ASSERT (!isinf (DBL_MIN / 2));
75 ASSERT (!isinf (-DBL_MIN / 2));
76 /* Finite values. */
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 ()));
88 /* Quiet NaN. */
89 ASSERT (!isinf (zerod / zerod));
90 #if HAVE_SNAND
91 /* Signalling NaN. */
92 ASSERT (!isinf (SNaNd ()));
93 #endif
96 static void
97 test_isinfl ()
99 /* Zero. */
100 ASSERT (!isinf (0.0L));
101 /* Subnormal values. */
102 ASSERT (!isinf (LDBL_MIN / 2));
103 ASSERT (!isinf (-LDBL_MIN / 2));
104 /* Finite values. */
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 ()));
116 /* Quiet NaN. */
117 ASSERT (!isinf (zerol / zerol));
118 #if HAVE_SNANL
119 /* Signalling NaN. */
120 ASSERT (!isinf (SNaNl ()));
121 #endif
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
124 #define NWORDS \
125 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
126 typedef union { unsigned int word[NWORDS]; long double value; }
127 memory_long_double;
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 \
136 # else
137 # define LDBL80_WORDS(exponent,manthi,mantlo) \
138 { mantlo, manthi, exponent }
139 # endif
140 { /* Quiet NaN. */
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. */
152 { /* Pseudo-NaN. */
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));
162 { /* Pseudo-Zero. */
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));
177 #undef NWORDS
178 #endif
182 main ()
184 test_isinff ();
185 test_isinfd ();
186 test_isinfl ();
187 return test_exit_status;