]>
Commit | Line | Data |
---|---|---|
846d9a4a | 1 | /* Test nearbyint functions do not clear exceptions (bug 15491). |
04277e02 | 2 | Copyright (C) 2015-2019 Free Software Foundation, Inc. |
846d9a4a JM |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #include <fenv.h> | |
20 | #include <math.h> | |
e082ac75 | 21 | #include <stdbool.h> |
846d9a4a JM |
22 | #include <stdio.h> |
23 | ||
24 | #include <math-tests.h> | |
25 | ||
26 | #ifndef FE_INVALID | |
27 | # define FE_INVALID 0 | |
28 | #endif | |
29 | ||
e082ac75 JM |
30 | static bool any_supported = false; |
31 | ||
846d9a4a JM |
32 | #define TEST_FUNC(NAME, FLOAT, SUFFIX) \ |
33 | static int \ | |
34 | NAME (void) \ | |
35 | { \ | |
36 | int result = 0; \ | |
e082ac75 JM |
37 | if (!EXCEPTION_TESTS (FLOAT)) \ |
38 | return 0; \ | |
39 | any_supported = true; \ | |
846d9a4a JM |
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. */ \ | |
e082ac75 | 53 | if (SNAN_TESTS (FLOAT)) \ |
846d9a4a JM |
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; \ | |
68 | } | |
69 | ||
70 | TEST_FUNC (float_test, float, f) | |
71 | TEST_FUNC (double_test, double, ) | |
846d9a4a | 72 | TEST_FUNC (ldouble_test, long double, l) |
846d9a4a JM |
73 | |
74 | static int | |
75 | do_test (void) | |
76 | { | |
77 | int result = float_test (); | |
78 | result |= double_test (); | |
846d9a4a | 79 | result |= ldouble_test (); |
e082ac75 JM |
80 | if (!any_supported) |
81 | return 77; | |
846d9a4a JM |
82 | return result; |
83 | } | |
84 | ||
85 | #define TEST_FUNCTION do_test () | |
86 | #include "../test-skeleton.c" |