pthread-once tests: Fix crash on mingw.
[gnulib.git] / tests / test-fenv-except-state-4.c
blobfa7afb298a6574ced7df474e42fb232474d4ccb6
1 /* Test of saving the floating-point exception status flags.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
19 #include <config.h>
21 /* Specification. */
22 #include <fenv.h>
24 #include "macros.h"
26 int
27 main ()
29 fexcept_t saved_flags_1;
30 fexcept_t saved_flags_2;
32 /* Test setting all exception flags. */
33 if (feraiseexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) != 0)
35 fputs ("Skipping test: floating-point exceptions are not supported on this machine.\n", stderr);
36 return 77;
39 /* Fill saved_flags_1. */
40 ASSERT (fegetexceptflag (&saved_flags_1,
41 FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
42 == 0);
43 /* Check its contents. */
44 ASSERT (fetestexceptflag (&saved_flags_1,
45 FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
46 == (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT));
47 ASSERT (fetestexceptflag (&saved_flags_1, FE_INVALID) == FE_INVALID);
48 ASSERT (fetestexceptflag (&saved_flags_1, FE_DIVBYZERO) == FE_DIVBYZERO);
49 ASSERT (fetestexceptflag (&saved_flags_1, FE_OVERFLOW) == FE_OVERFLOW);
50 ASSERT (fetestexceptflag (&saved_flags_1, FE_UNDERFLOW) == FE_UNDERFLOW);
51 ASSERT (fetestexceptflag (&saved_flags_1, FE_INEXACT) == FE_INEXACT);
53 /* Clear some of the exception flags. */
54 ASSERT (feclearexcept (FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) == 0);
55 /* Here, the set exception flags are FE_INVALID | FE_DIVBYZERO. */
56 ASSERT (fetestexcept (FE_INVALID) == FE_INVALID);
57 ASSERT (fetestexcept (FE_DIVBYZERO) == FE_DIVBYZERO);
58 ASSERT (fetestexcept (FE_OVERFLOW) == 0);
59 ASSERT (fetestexcept (FE_UNDERFLOW) == 0);
60 ASSERT (fetestexcept (FE_INEXACT) == 0);
62 /* Fill saved_flags_2. */
63 ASSERT (fegetexceptflag (&saved_flags_2, FE_INVALID | FE_OVERFLOW) == 0);
64 /* Check its contents. */
65 ASSERT (fetestexceptflag (&saved_flags_2, FE_INVALID | FE_OVERFLOW) == FE_INVALID);
66 ASSERT (fetestexceptflag (&saved_flags_2, FE_INVALID) == FE_INVALID);
67 ASSERT (fetestexceptflag (&saved_flags_2, FE_OVERFLOW) == 0);
69 return test_exit_status;