openat: don’t close (-1)
[gnulib.git] / tests / test-setpayloadsigl.c
blob0286d16d332a1c53b6159593db1147ef33794a03
1 /* Test setpayloadsigl.
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 (setpayloadsigl, int, (long double *, long double));
25 #include <float.h>
27 #include "infinity.h"
28 #include "isnanl-nolibm.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 int i;
44 long double p;
47 /* Test valid payloads. */
48 for (i = 0, p = 1.0L; i < PAYLOAD_BITS; i++, p *= 2.0L)
50 int ret;
51 long double x;
53 ret = setpayloadsigl (&x, p);
54 ASSERT (ret == 0);
55 ASSERT (isnanl (x));
57 /* Test out-of-range payload. */
58 int ret;
59 long double x;
61 ret = setpayloadsigl (&x, p);
62 ASSERT (ret != 0);
63 ASSERT (x == 0.0L);
66 /* Test infinite payload. */
68 int ret;
69 long double x;
71 ret = setpayloadsigl (&x, Infinityl ());
72 ASSERT (ret != 0);
73 ASSERT (x == 0.0L);
76 /* Test negative payload. */
78 int ret;
79 long double x;
81 ret = setpayloadsigl (&x, -1.0L);
82 ASSERT (ret != 0);
83 ASSERT (x == 0.0L);
86 /* Test fractional payload. */
88 int ret;
89 long double x;
91 ret = setpayloadsigl (&x, 1.4L);
92 ASSERT (ret != 0);
93 ASSERT (x == 0.0L);
96 return test_exit_status;