maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-getpayload.c
blobc0047a82ecb0895205b1be021880129b9991fd57
1 /* Test getpayload.
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 (getpayload, double, (const 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 #define PAYLOAD_BITS (53 - 2) /* = (DBL_MANT_DIG - 2) */
33 int
34 main ()
36 double arg;
37 double ret;
39 /* Test non-NaN arguments. */
41 arg = 2.718281828459045;
42 ret = getpayload (&arg);
43 ASSERT (ret == -1.0);
45 arg = -3.141592653589793;
46 ret = getpayload (&arg);
47 ASSERT (ret == -1.0);
49 arg = 0.0;
50 ret = getpayload (&arg);
51 ASSERT (ret == -1.0);
53 arg = minus_zerod;
54 ret = getpayload (&arg);
55 ASSERT (ret == -1.0);
57 arg = Infinityd ();
58 ret = getpayload (&arg);
59 ASSERT (ret == -1.0);
61 arg = - Infinityd ();
62 ret = getpayload (&arg);
63 ASSERT (ret == -1.0);
65 /* Test quiet NaNs. */
67 int i;
68 double p;
70 for (i = 0, p = 1.0; i < PAYLOAD_BITS; i++, p *= 2.0)
72 ASSERT (setpayload (&arg, p) == 0);
73 ret = getpayload (&arg);
74 ASSERT (ret == p);
75 /* Test quiet NaNs with sign bit == 1. */
76 arg = minus_NaNd (arg);
77 ret = getpayload (&arg);
78 ASSERT (ret == p);
81 p = 1320699239819071.0;
82 ASSERT (setpayload (&arg, p) == 0);
83 ret = getpayload (&arg);
84 ASSERT (ret == p);
87 /* Test signalling NaNs. */
89 int i;
90 double p;
92 for (i = 0, p = 1.0; i < PAYLOAD_BITS; i++, p *= 2.0)
94 ASSERT (setpayloadsig (&arg, p) == 0);
95 ret = getpayload (&arg);
96 ASSERT (ret == p);
99 p = 1320699239819071.0;
100 ASSERT (setpayloadsig (&arg, p) == 0);
101 ret = getpayload (&arg);
102 ASSERT (ret == p);
104 /* Test signalling NaNs with sign bit == 1. */
105 memory_double pos_arg = memory_positive_SNaNd ();
106 memory_double neg_arg = memory_negative_SNaNd ();
107 double pos_ret = getpayload (&pos_arg.value);
108 double neg_ret = getpayload (&neg_arg.value);
109 ASSERT (neg_ret == pos_ret);
112 return test_exit_status;