1 /* Test of tracking of floating-point exceptions.
2 Copyright (C) 2023-2025 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. */
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. */
38 main (int argc
, char *argv
[])
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]);
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
);
65 feraiseexcept (exception
);
68 return test_exit_status
;
76 fputs ("Skipping test: feenableexcept not available\n", stderr
);