1 /* Test for the C++ implementation of iszero.
2 Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>. */
28 check (int actual
, int expected
, const char *actual_expr
, int line
)
30 if (actual
!= expected
)
33 printf ("%s:%d: error: %s\n", __FILE__
, line
, actual_expr
);
34 printf ("%s:%d: expected: %d\n", __FILE__
, line
, expected
);
35 printf ("%s:%d: actual: %d\n", __FILE__
, line
, actual
);
39 #define CHECK(actual, expected) \
40 check ((actual), (expected), #actual, __LINE__)
46 typedef std::numeric_limits
<T
> limits
;
47 CHECK (iszero (T
{}), 1);
48 CHECK (iszero (T
{0}), 1);
49 CHECK (iszero (T
{-0.0}), 1);
50 CHECK (iszero (T
{1}), 0);
51 CHECK (iszero (T
{-1}), 0);
52 CHECK (iszero (limits::min ()), 0);
53 CHECK (iszero (-limits::min ()), 0);
54 CHECK (iszero (limits::max ()), 0);
55 CHECK (iszero (-limits::max ()), 0);
56 if (limits::has_infinity
)
58 CHECK (iszero (limits::infinity ()), 0);
59 CHECK (iszero (-limits::infinity ()), 0);
61 CHECK (iszero (limits::epsilon ()), 0);
62 CHECK (iszero (-limits::epsilon ()), 0);
63 if (limits::has_quiet_NaN
)
64 CHECK (iszero (limits::quiet_NaN ()), 0);
65 if (limits::has_signaling_NaN
)
66 CHECK (iszero (limits::signaling_NaN ()), 0);
67 if (limits::has_signaling_NaN
)
68 CHECK (iszero (limits::signaling_NaN ()), 0);
69 CHECK (iszero (limits::denorm_min ()),
70 std::numeric_limits
<T
>::has_denorm
== std::denorm_absent
);
71 CHECK (iszero (-limits::denorm_min ()),
72 std::numeric_limits
<T
>::has_denorm
== std::denorm_absent
);
79 check_type
<double> ();
80 check_type
<long double> ();
84 #define TEST_FUNCTION do_test ()
85 #include "../test-skeleton.c"