usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-fenv-except-tracking-4.c
blob5f77f830d9abd3b510c38d5a188c141a913c9431
1 /* Test of tracking of floating-point exceptions.
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 /* Check that fesetexcept() works. */
28 /* On *BSD/powerpc systems, raising FE_INVALID also sets FE_VXSOFT. */
29 #ifndef FE_VXSOFT
30 # define FE_VXSOFT 0
31 #endif
33 int
34 main ()
36 /* Test setting all exception flags. */
37 if (feraiseexcept (FE_ALL_EXCEPT) != 0)
39 fputs ("Skipping test: floating-point exceptions are not supported on this machine.\n", stderr);
40 return 77;
43 /* Clear all exception flags. */
44 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
47 /* Test setting just one exception flag: FE_INVALID. */
48 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
49 ASSERT (fesetexcept (FE_INVALID) == 0);
50 ASSERT ((fetestexcept (FE_ALL_EXCEPT) & ~FE_VXSOFT) == FE_INVALID);
51 ASSERT (fetestexcept (FE_INVALID) == FE_INVALID);
52 ASSERT (fetestexcept (FE_DIVBYZERO) == 0);
53 ASSERT (fetestexcept (FE_OVERFLOW) == 0);
54 ASSERT (fetestexcept (FE_UNDERFLOW) == 0);
55 ASSERT (fetestexcept (FE_INEXACT) == 0);
57 /* Test setting just one exception flag: FE_DIVBYZERO. */
58 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
59 ASSERT (fesetexcept (FE_DIVBYZERO) == 0);
60 ASSERT (fetestexcept (FE_ALL_EXCEPT) == FE_DIVBYZERO);
61 ASSERT (fetestexcept (FE_INVALID) == 0);
62 ASSERT (fetestexcept (FE_DIVBYZERO) == FE_DIVBYZERO);
63 ASSERT (fetestexcept (FE_OVERFLOW) == 0);
64 ASSERT (fetestexcept (FE_UNDERFLOW) == 0);
65 ASSERT (fetestexcept (FE_INEXACT) == 0);
67 /* Test setting just one exception flag: FE_OVERFLOW. */
68 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
69 ASSERT (fesetexcept (FE_OVERFLOW) == 0);
70 ASSERT (fetestexcept (FE_ALL_EXCEPT) == FE_OVERFLOW);
71 ASSERT (fetestexcept (FE_INVALID) == 0);
72 ASSERT (fetestexcept (FE_DIVBYZERO) == 0);
73 ASSERT (fetestexcept (FE_OVERFLOW) == FE_OVERFLOW);
74 ASSERT (fetestexcept (FE_UNDERFLOW) == 0);
75 ASSERT (fetestexcept (FE_INEXACT) == 0);
77 /* Test setting just one exception flag: FE_UNDERFLOW. */
78 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
79 ASSERT (fesetexcept (FE_UNDERFLOW) == 0);
80 ASSERT (fetestexcept (FE_ALL_EXCEPT) == FE_UNDERFLOW);
81 ASSERT (fetestexcept (FE_INVALID) == 0);
82 ASSERT (fetestexcept (FE_DIVBYZERO) == 0);
83 ASSERT (fetestexcept (FE_OVERFLOW) == 0);
84 ASSERT (fetestexcept (FE_UNDERFLOW) == FE_UNDERFLOW);
85 ASSERT (fetestexcept (FE_INEXACT) == 0);
87 /* Test setting just one exception flag: FE_INEXACT. */
88 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
89 ASSERT (fesetexcept (FE_INEXACT) == 0);
90 ASSERT (fetestexcept (FE_ALL_EXCEPT) == FE_INEXACT);
91 ASSERT (fetestexcept (FE_INVALID) == 0);
92 ASSERT (fetestexcept (FE_DIVBYZERO) == 0);
93 ASSERT (fetestexcept (FE_OVERFLOW) == 0);
94 ASSERT (fetestexcept (FE_UNDERFLOW) == 0);
95 ASSERT (fetestexcept (FE_INEXACT) == FE_INEXACT);
98 return test_exit_status;