]>
Commit | Line | Data |
---|---|---|
846d9a4a | 1 | /* Test nearbyint functions do not clear exceptions (bug 15491). |
f7a9f785 | 2 | Copyright (C) 2015-2016 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> | |
21 | #include <stdio.h> | |
22 | ||
23 | #include <math-tests.h> | |
24 | ||
25 | #ifndef FE_INVALID | |
26 | # define FE_INVALID 0 | |
27 | #endif | |
28 | ||
29 | #define TEST_FUNC(NAME, FLOAT, SUFFIX) \ | |
30 | static int \ | |
31 | NAME (void) \ | |
32 | { \ | |
33 | int result = 0; \ | |
34 | volatile FLOAT a, b __attribute__ ((unused)); \ | |
35 | a = 1.0; \ | |
36 | /* nearbyint must not clear already-raised exceptions. */ \ | |
37 | feraiseexcept (FE_ALL_EXCEPT); \ | |
38 | b = nearbyint ## SUFFIX (a); \ | |
39 | if (fetestexcept (FE_ALL_EXCEPT) == FE_ALL_EXCEPT) \ | |
40 | puts ("PASS: " #FLOAT); \ | |
41 | else \ | |
42 | { \ | |
43 | puts ("FAIL: " #FLOAT); \ | |
44 | result = 1; \ | |
45 | } \ | |
46 | /* But it mustn't lose exceptions from sNaN arguments. */ \ | |
47 | if (SNAN_TESTS (FLOAT) && EXCEPTION_TESTS (FLOAT)) \ | |
48 | { \ | |
49 | static volatile FLOAT snan = __builtin_nans ## SUFFIX (""); \ | |
50 | volatile FLOAT c __attribute__ ((unused)); \ | |
51 | feclearexcept (FE_ALL_EXCEPT); \ | |
52 | c = nearbyint ## SUFFIX (snan); \ | |
53 | if (fetestexcept (FE_INVALID) == FE_INVALID) \ | |
54 | puts ("PASS: " #FLOAT " sNaN"); \ | |
55 | else \ | |
56 | { \ | |
57 | puts ("FAIL: " #FLOAT " sNaN"); \ | |
58 | result = 1; \ | |
59 | } \ | |
60 | } \ | |
61 | return result; \ | |
62 | } | |
63 | ||
64 | TEST_FUNC (float_test, float, f) | |
65 | TEST_FUNC (double_test, double, ) | |
66 | #ifndef NO_LONG_DOUBLE | |
67 | TEST_FUNC (ldouble_test, long double, l) | |
68 | #endif | |
69 | ||
70 | static int | |
71 | do_test (void) | |
72 | { | |
73 | int result = float_test (); | |
74 | result |= double_test (); | |
75 | #ifndef NO_LONG_DOUBLE | |
76 | result |= ldouble_test (); | |
77 | #endif | |
78 | return result; | |
79 | } | |
80 | ||
81 | #define TEST_FUNCTION do_test () | |
82 | #include "../test-skeleton.c" |