maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-fenv-except-tracking-5.c
blobfe8b6063e6c88f42745681171821ed6c1bec4c3d
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 <stdio.h>
26 #include "fpe-trapping.h"
27 #include "macros.h"
29 /* musl libc does not support floating-point exception trapping, even where
30 the hardware supports it. See
31 <https://wiki.musl-libc.org/functional-differences-from-glibc.html> */
32 #if HAVE_FPE_TRAPPING && (!MUSL_LIBC || GNULIB_FEENABLEEXCEPT)
34 /* Check that fesetexcept() does not trigger a trap. */
36 static volatile double a, b;
37 static volatile long double al, bl;
39 int
40 main ()
42 /* Clear FE_INVALID exceptions from past operations. */
43 feclearexcept (FE_INVALID);
45 /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default
46 terminates the program. */
47 if (sigfpe_on_invalid () < 0)
49 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr);
50 return 77;
53 /* Attempt to set the FE_INVALID exception flag. */
54 _GL_UNUSED int rc = fesetexcept (FE_INVALID);
55 /* On older i386 and on PowerPC, there is no way to implement
56 fesetexcept() such that it does not trigger a trap. fesetexcept()
57 is expected to fail in this case. */
58 # if !((defined __i386 || defined _M_IX86) || defined __powerpc__)
59 ASSERT (rc == 0);
60 # endif
62 /* Do a harmless floating-point operation (since on some CPUs, floating-point
63 exceptions trigger a trap only at the next floating-point operation). */
64 a = 1.0; b = a + a;
65 al = 1.0L; bl = al + al;
67 return test_exit_status;
70 #else
72 int
73 main ()
75 fputs ("Skipping test: feenableexcept not available\n", stderr);
76 return 77;
79 #endif