1 /* Test for the C++ implementation of issignaling.
2 Copyright (C) 2017-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 /* There is no signaling_NaN for _Float128 in std::numeric_limits.
26 Include ieee754_float128.h and use the bitfields in the union
27 ieee854_float128.ieee_nan to build a signaling NaN. */
28 #if __HAVE_DISTINCT_FLOAT128
29 # include <ieee754_float128.h>
35 check (int actual
, int expected
, const char *actual_expr
, int line
)
37 if (actual
!= expected
)
40 printf ("%s:%d: error: %s\n", __FILE__
, line
, actual_expr
);
41 printf ("%s:%d: expected: %d\n", __FILE__
, line
, expected
);
42 printf ("%s:%d: actual: %d\n", __FILE__
, line
, actual
);
46 #define CHECK(actual, expected) \
47 check ((actual), (expected), #actual, __LINE__)
53 typedef std::numeric_limits
<T
> limits
;
54 CHECK (issignaling (T
{0}), 0);
55 if (limits::has_infinity
)
57 CHECK (issignaling (limits::infinity ()), 0);
58 CHECK (issignaling (-limits::infinity ()), 0);
60 if (limits::has_quiet_NaN
)
61 CHECK (issignaling (limits::quiet_NaN ()), 0);
62 if (limits::has_signaling_NaN
)
63 CHECK (issignaling (limits::signaling_NaN ()), 1);
66 #if __HAVE_DISTINCT_FLOAT128
73 CHECK (issignaling (q
.d
), 0);
77 q
.ieee
.exponent
= 0x7FFF;
78 q
.ieee
.mantissa0
= 0x0000;
79 q
.ieee
.mantissa1
= 0x00000000;
80 q
.ieee
.mantissa2
= 0x00000000;
81 q
.ieee
.mantissa3
= 0x00000000;
82 CHECK (issignaling (q
.d
), 0);
85 q
.ieee_nan
.quiet_nan
= 1;
86 q
.ieee_nan
.mantissa0
= 0x0000;
87 CHECK (issignaling (q
.d
), 0);
89 /* Still a quiet NaN. */
90 q
.ieee_nan
.quiet_nan
= 1;
91 q
.ieee_nan
.mantissa0
= 0x4000;
92 CHECK (issignaling (q
.d
), 0);
95 q
.ieee_nan
.quiet_nan
= 0;
96 q
.ieee_nan
.mantissa0
= 0x4000;
97 CHECK (issignaling (q
.d
), 1);
104 check_type
<float> ();
105 check_type
<double> ();
106 check_type
<long double> ();
107 #if __HAVE_DISTINCT_FLOAT128
113 #include <support/test-driver.c>