]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/test-fenv-return.c
Fix the inaccuracy of j0f/j1f/y0f/y1f [BZ #14469, #14470, #14471, #14472]
[thirdparty/glibc.git] / math / test-fenv-return.c
1 /* Test return value when setting FE_NOMASK_ENV (BZ16918, BZ17009).
2 Copyright (C) 2014-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 <stdio.h>
21 #include <math-tests.h>
22
23 static int count_errors;
24
25 static void
26 test_feenableexcept (void)
27 {
28 #if defined FE_ALL_EXCEPT
29 int res;
30
31 fedisableexcept (FE_ALL_EXCEPT);
32
33 res = feenableexcept (FE_ALL_EXCEPT);
34
35 if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res == -1))
36 {
37 puts ("feenableexcept (FE_ALL_EXCEPT) not supported, cannot test.");
38 return;
39 }
40 else if (res != 0)
41 {
42 puts ("feenableexcept (FE_ALL_EXCEPT) failed");
43 count_errors++;
44 }
45
46 if (fegetexcept () != FE_ALL_EXCEPT)
47 {
48 puts ("feenableexcept did not set all exceptions");
49 count_errors++;
50 }
51 #endif
52 }
53
54 static void
55 test_fesetenv (void)
56 {
57 #if defined FE_NOMASK_ENV && defined FE_ALL_EXCEPT
58 int res;
59
60 fedisableexcept (FE_ALL_EXCEPT);
61
62 res = fesetenv (FE_NOMASK_ENV);
63
64 if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res != 0))
65 {
66 puts ("fesetenv (FE_NOMASK_ENV) not supported, cannot test.");
67 return;
68 }
69 else if (res != 0)
70 {
71 puts ("fesetenv (FE_NOMASK_ENV) failed");
72 count_errors++;
73 }
74
75 if (fegetexcept () != FE_ALL_EXCEPT)
76 {
77 puts ("fesetenv did not set all exceptions");
78 count_errors++;
79 }
80 #endif
81 }
82
83 static void
84 test_feupdateenv (void)
85 {
86 #if defined FE_NOMASK_ENV && defined FE_ALL_EXCEPT
87 int res;
88
89 fedisableexcept (FE_ALL_EXCEPT);
90
91 res = feupdateenv (FE_NOMASK_ENV);
92
93 if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res != 0))
94 {
95 puts ("feupdateenv (FE_NOMASK_ENV)) not supported, cannot test.");
96 return;
97 }
98 else if (res != 0)
99 {
100 puts ("feupdateenv (FE_NOMASK_ENV) failed");
101 count_errors++;
102 }
103
104 if (fegetexcept () != FE_ALL_EXCEPT)
105 {
106 puts ("feupdateenv did not set all exceptions");
107 count_errors++;
108 }
109 #endif
110 }
111
112 static int
113 do_test (void)
114 {
115 test_feenableexcept ();
116 test_fesetenv ();
117 test_feupdateenv ();
118
119 return count_errors != 0 ? 1 : 0;
120 }
121
122 #define TEST_FUNCTION do_test ()
123 #include "../test-skeleton.c"