]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/test-nearbyint-except-2.c
Fix the inaccuracy of j0f/j1f/y0f/y1f [BZ #14469, #14470, #14471, #14472]
[thirdparty/glibc.git] / math / test-nearbyint-except-2.c
1 /* Test nearbyint functions do not disable exception traps (bug 19228).
2 Copyright (C) 2015-2021 Free Software Foundation, Inc.
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 <https://www.gnu.org/licenses/>. */
18
19 #include <fenv.h>
20 #include <math.h>
21 #include <stdio.h>
22
23 #ifndef FE_INEXACT
24 # define FE_INEXACT 0
25 #endif
26
27 #define TEST_FUNC(NAME, FLOAT, SUFFIX) \
28 static int \
29 NAME (void) \
30 { \
31 int result = 0; \
32 volatile FLOAT a, b __attribute__ ((unused)); \
33 a = 1.5; \
34 /* nearbyint must work when traps on "inexact" are enabled. */ \
35 b = nearbyint ## SUFFIX (a); \
36 /* And it must have left those traps enabled. */ \
37 if (fegetexcept () == FE_INEXACT) \
38 puts ("PASS: " #FLOAT); \
39 else \
40 { \
41 puts ("FAIL: " #FLOAT); \
42 result = 1; \
43 } \
44 return result; \
45 }
46
47 TEST_FUNC (float_test, float, f)
48 TEST_FUNC (double_test, double, )
49 TEST_FUNC (ldouble_test, long double, l)
50
51 static int
52 do_test (void)
53 {
54 if (feenableexcept (FE_INEXACT) == -1)
55 {
56 puts ("enabling FE_INEXACT traps failed, cannot test");
57 return 77;
58 }
59 int result = float_test ();
60 feenableexcept (FE_INEXACT);
61 result |= double_test ();
62 feenableexcept (FE_INEXACT);
63 result |= ldouble_test ();
64 return result;
65 }
66
67 #define TEST_FUNCTION do_test ()
68 #include "../test-skeleton.c"