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/>. */
22 #include "signature.h"
23 SIGNATURE_CHECK (getpayloadl
, long double, (const long double *));
25 #include "minus-zero.h"
27 #include "signed-nan.h"
28 #include "signed-snan.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)
37 # define PAYLOAD_BITS (LDBL_MANT_DIG - 2)
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);
57 ret
= getpayloadl (&arg
);
58 ASSERT (ret
== -1.0L);
61 ret
= getpayloadl (&arg
);
62 ASSERT (ret
== -1.0L);
65 ret
= getpayloadl (&arg
);
66 ASSERT (ret
== -1.0L);
69 ret
= getpayloadl (&arg
);
70 ASSERT (ret
== -1.0L);
72 /* Test quiet NaNs. */
77 for (i
= 0, p
= 1.0L; i
< PAYLOAD_BITS
; i
++, p
*= 2.0L)
79 ASSERT (setpayloadl (&arg
, p
) == 0);
80 ret
= getpayloadl (&arg
);
82 /* Test quiet NaNs with sign bit == 1. */
83 arg
= minus_NaNl (arg
);
84 ret
= getpayloadl (&arg
);
88 p
= 1320699239819071.0L;
89 ASSERT (setpayloadl (&arg
, p
) == 0);
90 ret
= getpayloadl (&arg
);
94 /* Test signalling NaNs. */
99 for (i
= 0, p
= 1.0L; i
< PAYLOAD_BITS
; i
++, p
*= 2.0L)
101 ASSERT (setpayloadsigl (&arg
, p
) == 0);
102 ret
= getpayloadl (&arg
);
106 p
= 1320699239819071.0L;
107 ASSERT (setpayloadsigl (&arg
, p
) == 0);
108 ret
= getpayloadl (&arg
);
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
;