1 /* Test nearbyint functions do not clear exceptions (bug 15491).
2 Copyright (C) 2015-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/>. */
24 #include <math-tests.h>
30 static bool any_supported
= false;
32 #define TEST_FUNC(NAME, FLOAT, SUFFIX) \
37 if (!EXCEPTION_TESTS (FLOAT)) \
39 any_supported = true; \
40 volatile FLOAT a, b __attribute__ ((unused)); \
42 /* nearbyint must not clear already-raised exceptions. */ \
43 feraiseexcept (FE_ALL_EXCEPT); \
44 b = nearbyint ## SUFFIX (a); \
45 if (fetestexcept (FE_ALL_EXCEPT) == FE_ALL_EXCEPT) \
46 puts ("PASS: " #FLOAT); \
49 puts ("FAIL: " #FLOAT); \
52 /* But it mustn't lose exceptions from sNaN arguments. */ \
53 if (SNAN_TESTS (FLOAT)) \
55 static volatile FLOAT snan = __builtin_nans ## SUFFIX (""); \
56 volatile FLOAT c __attribute__ ((unused)); \
57 feclearexcept (FE_ALL_EXCEPT); \
58 c = nearbyint ## SUFFIX (snan); \
59 if (fetestexcept (FE_INVALID) == FE_INVALID) \
60 puts ("PASS: " #FLOAT " sNaN"); \
63 puts ("FAIL: " #FLOAT " sNaN"); \
70 TEST_FUNC (float_test
, float, f
)
71 TEST_FUNC (double_test
, double, )
72 #ifndef NO_LONG_DOUBLE
73 TEST_FUNC (ldouble_test
, long double, l
)
79 int result
= float_test ();
80 result
|= double_test ();
81 #ifndef NO_LONG_DOUBLE
82 result
|= ldouble_test ();
89 #define TEST_FUNCTION do_test ()
90 #include "../test-skeleton.c"