openat: don’t close (-1)
[gnulib.git] / tests / test-signbit.c
blob1269b084a50c97f1006f637ff19d48d87edc5c33
1 /* Test of signbit() 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 Bruno Haible <bruno@clisp.org>, 2007. */
19 #include <config.h>
21 #include <math.h>
23 /* signbit must be a macro. */
24 #ifndef signbit
25 # error missing declaration
26 #endif
28 #include <float.h>
29 #include <limits.h>
31 #include "minus-zero.h"
32 #include "infinity.h"
33 #include "signed-nan.h"
34 #include "signed-snan.h"
35 #include "macros.h"
37 float zerof = 0.0f;
38 double zerod = 0.0;
39 long double zerol = 0.0L;
41 static void
42 test_signbitf ()
44 /* Finite values. */
45 ASSERT (!signbit (3.141f));
46 ASSERT (!signbit (3.141e30f));
47 ASSERT (!signbit (3.141e-30f));
48 ASSERT (signbit (-2.718f));
49 ASSERT (signbit (-2.718e30f));
50 ASSERT (signbit (-2.718e-30f));
51 /* Zeros. */
52 ASSERT (!signbit (0.0f));
53 if (1.0f / minus_zerof < 0)
54 ASSERT (signbit (minus_zerof));
55 else
56 ASSERT (!signbit (minus_zerof));
57 /* Infinite values. */
58 ASSERT (!signbit (Infinityf ()));
59 ASSERT (signbit (- Infinityf ()));
60 /* Quiet NaN. */
61 ASSERT (!signbit (positive_NaNf ()));
62 ASSERT (signbit (negative_NaNf ()));
63 #if HAVE_SNANF
64 /* Signalling NaN. */
65 ASSERT (!signbit (positive_SNaNf ()));
66 ASSERT (signbit (negative_SNaNf ()));
67 #endif
70 static void
71 test_signbitd ()
73 /* Finite values. */
74 ASSERT (!signbit (3.141));
75 ASSERT (!signbit (3.141e30));
76 ASSERT (!signbit (3.141e-30));
77 ASSERT (signbit (-2.718));
78 ASSERT (signbit (-2.718e30));
79 ASSERT (signbit (-2.718e-30));
80 /* Zeros. */
81 ASSERT (!signbit (0.0));
82 if (1.0 / minus_zerod < 0)
83 ASSERT (signbit (minus_zerod));
84 else
85 ASSERT (!signbit (minus_zerod));
86 /* Infinite values. */
87 ASSERT (!signbit (Infinityd ()));
88 ASSERT (signbit (- Infinityd ()));
89 /* Quiet NaN. */
90 ASSERT (!signbit (positive_NaNd ()));
91 ASSERT (signbit (negative_NaNd ()));
92 #if HAVE_SNAND
93 /* Signalling NaN. */
94 ASSERT (!signbit (positive_SNaNd ()));
95 ASSERT (signbit (negative_SNaNd ()));
96 #endif
99 static void
100 test_signbitl ()
102 /* Finite values. */
103 ASSERT (!signbit (3.141L));
104 ASSERT (!signbit (3.141e30L));
105 ASSERT (!signbit (3.141e-30L));
106 ASSERT (signbit (-2.718L));
107 ASSERT (signbit (-2.718e30L));
108 ASSERT (signbit (-2.718e-30L));
109 /* Zeros. */
110 ASSERT (!signbit (0.0L));
111 if (1.0L / minus_zerol < 0)
112 ASSERT (signbit (minus_zerol));
113 else
114 ASSERT (!signbit (minus_zerol));
115 /* Infinite values. */
116 ASSERT (!signbit (Infinityl ()));
117 ASSERT (signbit (- Infinityl ()));
118 /* Quiet NaN. */
119 ASSERT (!signbit (positive_NaNl ()));
120 ASSERT (signbit (negative_NaNl ()));
121 #if HAVE_SNANL
122 /* Signalling NaN. */
123 ASSERT (!signbit (positive_SNaNl ()));
124 ASSERT (signbit (negative_SNaNl ()));
125 #endif
129 main ()
131 test_signbitf ();
132 test_signbitd ();
133 test_signbitl ();
134 return test_exit_status;