1 /* Test femode_t functions: test handling of exception traps.
2 Copyright (C) 2016-2023 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 <https://www.gnu.org/licenses/>. */
21 #include <math-tests.h>
24 test_ee (int exc1
, int exc2
)
27 printf ("testing %x %x\n", (unsigned int) exc1
, (unsigned int) exc2
);
29 fedisableexcept (FE_ALL_EXCEPT
);
30 int ret
= feenableexcept (exc1
);
33 if (EXCEPTION_ENABLE_SUPPORTED (exc1
))
35 puts ("first feenableexcept failed unexpectedly");
39 puts ("first feenableexcept failed, cannot test");
43 ret
= fegetmode (&saved
);
46 puts ("fegetmode failed");
50 fedisableexcept (FE_ALL_EXCEPT
);
51 ret
= feenableexcept (exc2
);
54 if (EXCEPTION_ENABLE_SUPPORTED (exc2
))
56 puts ("second feenableexcept failed unexpectedly");
60 puts ("second feenableexcept failed, cannot test");
63 ret
= fesetmode (&saved
);
66 puts ("fesetmode failed");
70 /* Verify that the set of enabled traps was restored. */
74 printf ("restored enabled traps %x not %x\n", (unsigned int) ret
,
78 /* Likewise, with default modes. */
79 ret
= fesetmode (FE_DFL_MODE
);
82 puts ("fesetmode (FE_DFL_MODE) failed");
89 printf ("FE_DFL_MODE enabled traps %x not 0\n", (unsigned int) ret
);
101 result
|= test_ee (exc1
, 0);
102 result
|= test_ee (exc1
, FE_ALL_EXCEPT
);
104 result
|= test_ee (exc1
, FE_DIVBYZERO
);
107 result
|= test_ee (exc1
, FE_INEXACT
);
110 result
|= test_ee (exc1
, FE_INVALID
);
113 result
|= test_ee (exc1
, FE_OVERFLOW
);
116 result
|= test_ee (exc1
, FE_UNDERFLOW
);
127 result
|= test_e (0);
128 result
|= test_e (FE_ALL_EXCEPT
);
130 result
|= test_e (FE_DIVBYZERO
);
133 result
|= test_e (FE_INEXACT
);
136 result
|= test_e (FE_INVALID
);
139 result
|= test_e (FE_OVERFLOW
);
142 result
|= test_e (FE_UNDERFLOW
);
148 #define TEST_FUNCTION do_test ()
149 #include "../test-skeleton.c"