1 /* Test fetestexceptflag.
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_one (int exc_test
, int exc_set
, int exc_save
)
28 printf ("Individual test: %x %x %x\n", (unsigned int) exc_test
,
29 (unsigned int) exc_set
, (unsigned int) exc_save
);
31 feclearexcept (FE_ALL_EXCEPT
);
32 int ret
= fesetexcept (exc_set
);
35 puts ("fesetexcept failed");
36 if (exc_set
== 0 || EXCEPTION_TESTS (float))
38 puts ("failure of fesetexcept was unexpected");
42 puts ("failure of fesetexcept OK, skipping further tests");
46 ret
= fegetexceptflag (&saved
, exc_save
);
48 puts ("fegetexceptflag succeeded");
51 puts ("fegetexceptflag failed");
55 ret
= fetestexceptflag (&saved
, exc_test
);
56 if (ret
== (exc_set
& exc_test
))
57 puts ("fetestexceptflag result correct");
60 printf ("fetestexceptflag returned %x, expected %x\n", ret
,
64 if (exc_save
== FE_ALL_EXCEPT
)
66 /* Also test fetestexceptflag testing all exceptions but
67 possibly with only some set. */
68 ret
= fetestexceptflag (&saved
, FE_ALL_EXCEPT
);
70 puts ("fetestexceptflag (FE_ALL_EXCEPT) result correct");
73 printf ("fetestexceptflag (FE_ALL_EXCEPT) returned %x, expected %x\n",
82 test_fetestexceptflag (int exc
, const char *exc_name
)
86 printf ("Testing %s\n", exc_name
);
88 /* Test each case of: whether this exception is set or clear;
89 whether other exceptions are set or clear; whether the whole
90 state is saved or just the state for this exception. */
91 result
|= test_one (exc
, 0, exc
);
92 result
|= test_one (exc
, 0, FE_ALL_EXCEPT
);
93 result
|= test_one (exc
, exc
, exc
);
94 result
|= test_one (exc
, exc
, FE_ALL_EXCEPT
);
95 result
|= test_one (exc
, FE_ALL_EXCEPT
& ~exc
, exc
);
96 result
|= test_one (exc
, FE_ALL_EXCEPT
& ~exc
, FE_ALL_EXCEPT
);
97 result
|= test_one (exc
, FE_ALL_EXCEPT
, exc
);
98 result
|= test_one (exc
, FE_ALL_EXCEPT
, FE_ALL_EXCEPT
);
108 result
|= test_fetestexceptflag (0, "0");
109 result
|= test_fetestexceptflag (FE_ALL_EXCEPT
, "FE_ALL_EXCEPT");
111 result
|= test_fetestexceptflag (FE_DIVBYZERO
, "FE_DIVBYZERO");
114 result
|= test_fetestexceptflag (FE_INEXACT
, "FE_INEXACT");
117 result
|= test_fetestexceptflag (FE_INVALID
, "FE_INVALID");
120 result
|= test_fetestexceptflag (FE_OVERFLOW
, "FE_OVERFLOW");
123 result
|= test_fetestexceptflag (FE_UNDERFLOW
, "FE_UNDERFLOW");
129 #define TEST_FUNCTION do_test ()
130 #include "../test-skeleton.c"