2 Copyright (C) 2016-2024 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_fesetexcept (int exc
, const char *exc_name
)
28 printf ("Testing %s\n", exc_name
);
29 feclearexcept (FE_ALL_EXCEPT
);
30 int ret
= fesetexcept (exc
);
32 printf ("fesetexcept (%s) succeeded\n", exc_name
);
35 printf ("fesetexcept (%s) failed\n", exc_name
);
36 if (exc
== 0 || EXCEPTION_TESTS (float))
38 puts ("failure of fesetexcept was unexpected");
42 puts ("failure of fesetexcept OK, skipping further tests");
45 ret
= fetestexcept (FE_ALL_EXCEPT
);
48 printf ("raised exceptions %x, expected %x\n",
49 (unsigned int) ret
, (unsigned int) exc
);
53 ret
= feraiseexcept (FE_ALL_EXCEPT
);
56 if (exc
== 0 && !EXCEPTION_TESTS (float))
58 puts ("feraiseexcept (FE_ALL_EXCEPT) failed, skipping further tests");
61 puts ("feraiseexcept (FE_ALL_EXCEPT) unexpectedly failed");
64 ret
= fesetexcept (exc
);
67 puts ("fesetexcept (second test) unexpectedly failed");
70 ret
= fetestexcept (FE_ALL_EXCEPT
);
71 if (ret
!= FE_ALL_EXCEPT
)
73 printf ("raised exceptions (second test) %x, expected %x\n",
74 (unsigned int) ret
, (unsigned int) FE_ALL_EXCEPT
);
78 feclearexcept (FE_ALL_EXCEPT
);
79 ret
= feraiseexcept (FE_ALL_EXCEPT
& ~exc
);
82 puts ("feraiseexcept (third test) unexpectedly failed");
85 ret
= fesetexcept (exc
);
88 puts ("fesetexcept (third test) unexpectedly failed");
91 ret
= fetestexcept (FE_ALL_EXCEPT
);
92 if (ret
!= FE_ALL_EXCEPT
)
94 printf ("raised exceptions (third test) %x, expected %x\n",
95 (unsigned int) ret
, (unsigned int) FE_ALL_EXCEPT
);
107 result
|= test_fesetexcept (0, "0");
108 result
|= test_fesetexcept (FE_ALL_EXCEPT
, "FE_ALL_EXCEPT");
110 result
|= test_fesetexcept (FE_DIVBYZERO
, "FE_DIVBYZERO");
113 result
|= test_fesetexcept (FE_INEXACT
, "FE_INEXACT");
116 result
|= test_fesetexcept (FE_INVALID
, "FE_INVALID");
119 result
|= test_fesetexcept (FE_OVERFLOW
, "FE_OVERFLOW");
122 result
|= test_fesetexcept (FE_UNDERFLOW
, "FE_UNDERFLOW");
128 #define TEST_FUNCTION do_test ()
129 #include "../test-skeleton.c"