1 /* Test femode_t functions.
2 Copyright (C) 2016-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/>. */
21 #include <math-tests.h>
24 test_mmee (int mode1
, int mode2
, int exc1
, int exc2
)
27 printf ("testing %x %x %x %x\n", (unsigned int) mode1
, (unsigned int) mode2
,
28 (unsigned int) exc1
, (unsigned int) exc2
);
30 feclearexcept (FE_ALL_EXCEPT
);
31 int ret
= fesetround (mode1
);
34 if (ROUNDING_TESTS (float, mode1
))
36 puts ("first fesetround failed unexpectedly");
40 puts ("first fesetround failed, cannot test");
43 ret
= fesetexcept (exc1
);
46 if (EXCEPTION_TESTS (float) || exc1
== 0)
48 puts ("first fesetexcept failed unexpectedly");
52 puts ("first fesetexcept failed, cannot test");
56 ret
= fegetmode (&saved
);
59 puts ("fegetmode failed");
63 feclearexcept (FE_ALL_EXCEPT
);
64 ret
= fesetround (mode2
);
67 if (ROUNDING_TESTS (float, mode2
))
69 puts ("second fesetround failed unexpectedly");
73 puts ("second fesetround failed, cannot test");
76 ret
= fesetexcept (exc2
);
79 if (EXCEPTION_TESTS (float) || exc2
== 0)
81 puts ("second fesetexcept failed unexpectedly");
85 puts ("second fesetexcept failed, cannot test");
88 ret
= fesetmode (&saved
);
91 puts ("fesetmode failed");
95 /* Verify that the rounding mode was restored but the exception
96 flags remain unchanged. */
100 printf ("restored rounding mode %x not %x\n", (unsigned int) ret
,
101 (unsigned int) mode1
);
104 ret
= fetestexcept (FE_ALL_EXCEPT
);
107 printf ("exceptions %x not %x\n", (unsigned int) ret
,
108 (unsigned int) exc2
);
111 /* Likewise, with default modes. */
112 ret
= fesetmode (FE_DFL_MODE
);
115 puts ("fesetmode (FE_DFL_MODE) failed");
120 if (ret
!= FE_TONEAREST
)
122 printf ("FE_DFL_MODE rounding mode %x not %x\n", (unsigned int) ret
,
123 (unsigned int) FE_TONEAREST
);
126 ret
= fetestexcept (FE_ALL_EXCEPT
);
129 printf ("FE_DFL_MODE exceptions %x not %x\n", (unsigned int) ret
,
130 (unsigned int) exc2
);
137 test_mme (int mode1
, int mode2
, int exc1
)
141 result
|= test_mmee (mode1
, mode2
, exc1
, 0);
142 result
|= test_mmee (mode1
, mode2
, exc1
, FE_ALL_EXCEPT
);
144 result
|= test_mmee (mode1
, mode2
, exc1
, FE_DIVBYZERO
);
147 result
|= test_mmee (mode1
, mode2
, exc1
, FE_INEXACT
);
150 result
|= test_mmee (mode1
, mode2
, exc1
, FE_INVALID
);
153 result
|= test_mmee (mode1
, mode2
, exc1
, FE_OVERFLOW
);
156 result
|= test_mmee (mode1
, mode2
, exc1
, FE_UNDERFLOW
);
163 test_mm (int mode1
, int mode2
)
167 result
|= test_mme (mode1
, mode2
, 0);
168 result
|= test_mme (mode1
, mode2
, FE_ALL_EXCEPT
);
170 result
|= test_mme (mode1
, mode2
, FE_DIVBYZERO
);
173 result
|= test_mme (mode1
, mode2
, FE_INEXACT
);
176 result
|= test_mme (mode1
, mode2
, FE_INVALID
);
179 result
|= test_mme (mode1
, mode2
, FE_OVERFLOW
);
182 result
|= test_mme (mode1
, mode2
, FE_UNDERFLOW
);
194 result
|= test_mm (mode1
, FE_DOWNWARD
);
197 result
|= test_mm (mode1
, FE_TONEAREST
);
200 result
|= test_mm (mode1
, FE_TOWARDZERO
);
203 result
|= test_mm (mode1
, FE_UPWARD
);
215 result
|= test_m (FE_DOWNWARD
);
218 result
|= test_m (FE_TONEAREST
);
221 result
|= test_m (FE_TOWARDZERO
);
224 result
|= test_m (FE_UPWARD
);
230 #define TEST_FUNCTION do_test ()
231 #include "../test-skeleton.c"