maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-fenv-except-tracking-3.c
blobd7fbde414c181cfc4dca9f07bb9923b90925595d
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>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "macros.h"
30 /* musl libc does not support floating-point exception trapping, even where
31 the hardware supports it. See
32 <https://wiki.musl-libc.org/functional-differences-from-glibc.html> */
33 #if !MUSL_LIBC || GNULIB_FEENABLEEXCEPT
35 /* Check that feraiseexcept() can trigger a trap. */
37 int
38 main (int argc, char *argv[])
40 if (argc > 1)
42 int exception;
44 if (STREQ (argv[1], "FE_INVALID")) exception = FE_INVALID; else
45 if (STREQ (argv[1], "FE_DIVBYZERO")) exception = FE_DIVBYZERO; else
46 if (STREQ (argv[1], "FE_OVERFLOW")) exception = FE_OVERFLOW; else
47 if (STREQ (argv[1], "FE_UNDERFLOW")) exception = FE_UNDERFLOW; else
48 if (STREQ (argv[1], "FE_INEXACT")) exception = FE_INEXACT; else
50 printf ("Invalid argument: %s\n", argv[1]);
51 exit (1);
54 /* Clear FE_XX exceptions from past operations. */
55 feclearexcept (exception);
57 /* An FE_XX exception shall trigger a SIGFPE signal, which by default
58 terminates the program. */
59 if (feenableexcept (exception) == -1)
61 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr);
62 return 77;
65 feraiseexcept (exception);
68 return test_exit_status;
71 #else
73 int
74 main ()
76 fputs ("Skipping test: feenableexcept not available\n", stderr);
77 return 77;
80 #endif