2 Copyright 2024-2025 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/>. */
22 #include "signature.h"
23 SIGNATURE_CHECK (getpayload
, double, (const double *));
25 #include "minus-zero.h"
27 #include "signed-nan.h"
28 #include "signed-snan.h"
31 #define PAYLOAD_BITS (53 - 2) /* = (DBL_MANT_DIG - 2) */
39 /* Test non-NaN arguments. */
41 arg
= 2.718281828459045;
42 ret
= getpayload (&arg
);
45 arg
= -3.141592653589793;
46 ret
= getpayload (&arg
);
50 ret
= getpayload (&arg
);
54 ret
= getpayload (&arg
);
58 ret
= getpayload (&arg
);
62 ret
= getpayload (&arg
);
65 /* Test quiet NaNs. */
70 for (i
= 0, p
= 1.0; i
< PAYLOAD_BITS
; i
++, p
*= 2.0)
72 ASSERT (setpayload (&arg
, p
) == 0);
73 ret
= getpayload (&arg
);
75 /* Test quiet NaNs with sign bit == 1. */
76 arg
= minus_NaNd (arg
);
77 ret
= getpayload (&arg
);
81 p
= 1320699239819071.0;
82 ASSERT (setpayload (&arg
, p
) == 0);
83 ret
= getpayload (&arg
);
87 /* Test signalling NaNs. */
92 for (i
= 0, p
= 1.0; i
< PAYLOAD_BITS
; i
++, p
*= 2.0)
94 ASSERT (setpayloadsig (&arg
, p
) == 0);
95 ret
= getpayload (&arg
);
99 p
= 1320699239819071.0;
100 ASSERT (setpayloadsig (&arg
, p
) == 0);
101 ret
= getpayload (&arg
);
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
;