openat: don’t close (-1)
[gnulib.git] / tests / test-getpayloadl.c
blobf7ebd2cf62af2d4b54615f2b2eb6b31503c2eaf7
1 /* Test getpayloadl.
2 Copyright 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 #include <config.h>
19 /* Specification. */
20 #include <math.h>
22 #include "signature.h"
23 SIGNATURE_CHECK (getpayloadl, long double, (const long double *));
25 #include "minus-zero.h"
26 #include "infinity.h"
27 #include "signed-nan.h"
28 #include "signed-snan.h"
29 #include "macros.h"
31 #if defined __powerpc__ && LDBL_MANT_DIG == 106
32 /* This is PowerPC "double double", a pair of two doubles. NaN is represented
33 as the corresponding 64-bit IEEE value in the first double; the second is
34 irrelevant and therefore does not contain a payload. */
35 # define PAYLOAD_BITS (DBL_MANT_DIG - 2)
36 #else
37 # define PAYLOAD_BITS (LDBL_MANT_DIG - 2)
38 #endif
40 int
41 main ()
43 long double arg;
44 long double ret;
46 /* Test non-NaN arguments. */
48 arg = 2.71828182845904523536028747135266249776L;
49 ret = getpayloadl (&arg);
50 ASSERT (ret == -1.0L);
52 arg = -3.1415926535897932384626433832795028842L;
53 ret = getpayloadl (&arg);
54 ASSERT (ret == -1.0L);
56 arg = 0.0L;
57 ret = getpayloadl (&arg);
58 ASSERT (ret == -1.0L);
60 arg = minus_zerol;
61 ret = getpayloadl (&arg);
62 ASSERT (ret == -1.0L);
64 arg = Infinityl ();
65 ret = getpayloadl (&arg);
66 ASSERT (ret == -1.0L);
68 arg = - Infinityl ();
69 ret = getpayloadl (&arg);
70 ASSERT (ret == -1.0L);
72 /* Test quiet NaNs. */
74 int i;
75 long double p;
77 for (i = 0, p = 1.0L; i < PAYLOAD_BITS; i++, p *= 2.0L)
79 ASSERT (setpayloadl (&arg, p) == 0);
80 ret = getpayloadl (&arg);
81 ASSERT (ret == p);
82 /* Test quiet NaNs with sign bit == 1. */
83 arg = minus_NaNl (arg);
84 ret = getpayloadl (&arg);
85 ASSERT (ret == p);
88 p = 1320699239819071.0L;
89 ASSERT (setpayloadl (&arg, p) == 0);
90 ret = getpayloadl (&arg);
91 ASSERT (ret == p);
94 /* Test signalling NaNs. */
96 int i;
97 long double p;
99 for (i = 0, p = 1.0L; i < PAYLOAD_BITS; i++, p *= 2.0L)
101 ASSERT (setpayloadsigl (&arg, p) == 0);
102 ret = getpayloadl (&arg);
103 ASSERT (ret == p);
106 p = 1320699239819071.0L;
107 ASSERT (setpayloadsigl (&arg, p) == 0);
108 ret = getpayloadl (&arg);
109 ASSERT (ret == p);
111 /* Test signalling NaNs with sign bit == 1. */
112 memory_long_double pos_arg = memory_positive_SNaNl ();
113 memory_long_double neg_arg = memory_negative_SNaNl ();
114 long double pos_ret = getpayloadl (&pos_arg.value);
115 long double neg_ret = getpayloadl (&neg_arg.value);
116 ASSERT (neg_ret == pos_ret);
119 return test_exit_status;