Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / math / test-nearbyint-except.c
blob42f5fa84cdb4b63543f3c4f80899eba4ac13afd6
1 /* Test nearbyint functions do not clear exceptions (bug 15491).
2 Copyright (C) 2015-2018 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/>. */
19 #include <fenv.h>
20 #include <math.h>
21 #include <stdbool.h>
22 #include <stdio.h>
24 #include <math-tests.h>
26 #ifndef FE_INVALID
27 # define FE_INVALID 0
28 #endif
30 static bool any_supported = false;
32 #define TEST_FUNC(NAME, FLOAT, SUFFIX) \
33 static int \
34 NAME (void) \
35 { \
36 int result = 0; \
37 if (!EXCEPTION_TESTS (FLOAT)) \
38 return 0; \
39 any_supported = true; \
40 volatile FLOAT a, b __attribute__ ((unused)); \
41 a = 1.0; \
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); \
47 else \
48 { \
49 puts ("FAIL: " #FLOAT); \
50 result = 1; \
51 } \
52 /* But it mustn't lose exceptions from sNaN arguments. */ \
53 if (SNAN_TESTS (FLOAT)) \
54 { \
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"); \
61 else \
62 { \
63 puts ("FAIL: " #FLOAT " sNaN"); \
64 result = 1; \
65 } \
66 } \
67 return result; \
70 TEST_FUNC (float_test, float, f)
71 TEST_FUNC (double_test, double, )
72 TEST_FUNC (ldouble_test, long double, l)
74 static int
75 do_test (void)
77 int result = float_test ();
78 result |= double_test ();
79 result |= ldouble_test ();
80 if (!any_supported)
81 return 77;
82 return result;
85 #define TEST_FUNCTION do_test ()
86 #include "../test-skeleton.c"