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. */
26 #include "fpe-trapping.h"
31 /* Check that triggering a floating-point operation can trigger a trap. */
34 main (int argc
, char *argv
[])
36 /* Clear FE_INVALID exceptions from past operations. */
37 feclearexcept (FE_INVALID
);
39 /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default
40 terminates the program. */
41 if (sigfpe_on_invalid () < 0)
43 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr
);
53 _GL_UNUSED
volatile float c
;
54 a
= 0; b
= 0; c
= a
/ b
;
61 _GL_UNUSED
volatile double c
;
62 a
= 0; b
= 0; c
= a
/ b
;
67 /* This test does not work on Linux/loongarch64 with glibc 2.37.
68 Likewise on Linux/alpha with glibc 2.7 on Linux 2.6.26.
69 Likewise on FreeBSD 12.2/sparc, NetBSD 8.0/sparc, OpenBSD 7.2/sparc64.
70 Likewise on OpenBSD 7.4/mips64.
72 #if !((__GLIBC__ >= 2 && defined __loongarch__) \
73 || ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36) && defined __alpha) \
74 || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && defined __sparc) \
75 || (defined __OpenBSD__ && defined __mips64))
77 volatile long double a
, b
;
78 _GL_UNUSED
volatile long double c
;
79 a
= 0; b
= 0; c
= a
/ b
;
82 fputs ("Skipping test: known failure on this platform\n", stderr
);
91 return test_exit_status
;
99 fputs ("Skipping test: feenableexcept not available\n", stderr
);