1 /* Test of signbit() substitute.
2 Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
23 /* signbit must be a macro. */
25 # error missing declaration
31 #include "minus-zero.h"
36 long double zerol = 0.0L;
42 ASSERT (!signbit (3.141f));
43 ASSERT (!signbit (3.141e30f));
44 ASSERT (!signbit (3.141e-30f));
45 ASSERT (signbit (-2.718f));
46 ASSERT (signbit (-2.718e30f));
47 ASSERT (signbit (-2.718e-30f));
49 ASSERT (!signbit (0.0f));
50 if (1.0f / minus_zerof < 0)
51 ASSERT (signbit (minus_zerof));
53 ASSERT (!signbit (minus_zerof));
54 /* Infinite values. */
55 ASSERT (!signbit (1.0f / 0.0f));
56 ASSERT (signbit (-1.0f / 0.0f));
58 (void) signbit (zerof / zerof);
59 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
63 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
64 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
66 m.value = zerof / zerof;
67 # if FLT_EXPBIT0_BIT > 0
68 m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
70 m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
71 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
73 if (FLT_EXPBIT0_WORD < NWORDS / 2)
74 m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
76 m.word[0] |= (unsigned int) 1;
77 (void) signbit (m.value);
87 ASSERT (!signbit (3.141));
88 ASSERT (!signbit (3.141e30));
89 ASSERT (!signbit (3.141e-30));
90 ASSERT (signbit (-2.718));
91 ASSERT (signbit (-2.718e30));
92 ASSERT (signbit (-2.718e-30));
94 ASSERT (!signbit (0.0));
95 if (1.0 / minus_zerod < 0)
96 ASSERT (signbit (minus_zerod));
98 ASSERT (!signbit (minus_zerod));
99 /* Infinite values. */
100 ASSERT (!signbit (1.0 / 0.0));
101 ASSERT (signbit (-1.0 / 0.0));
103 (void) signbit (zerod / zerod);
104 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
105 /* Signalling NaN. */
108 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
109 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
111 m.value = zerod / zerod;
112 # if DBL_EXPBIT0_BIT > 0
113 m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
115 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
116 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
118 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
119 |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
120 (void) signbit (m.value);
130 ASSERT (!signbit (3.141L));
131 ASSERT (!signbit (3.141e30L));
132 ASSERT (!signbit (3.141e-30L));
133 ASSERT (signbit (-2.718L));
134 ASSERT (signbit (-2.718e30L));
135 ASSERT (signbit (-2.718e-30L));
137 ASSERT (!signbit (0.0L));
138 if (1.0L / minus_zerol < 0)
139 ASSERT (signbit (minus_zerol));
141 ASSERT (!signbit (minus_zerol));
142 /* Infinite values. */
143 ASSERT (!signbit (1.0L / 0.0L));
144 ASSERT (signbit (-1.0L / 0.0L));
146 (void) signbit (zerol / zerol);
147 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
148 /* Signalling NaN. */
151 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
152 typedef union { long double value; unsigned int word[NWORDS]; } memory_long_double;
153 memory_long_double m;
154 m.value = zerol / zerol;
155 # if LDBL_EXPBIT0_BIT > 0
156 m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
158 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
159 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
161 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
162 |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
163 (void) signbit (m.value);