1 /* Tests of quiet not-a-number.
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. */
26 #include "fpe-trapping.h"
34 float volatile resultf
;
35 double volatile resultd
;
36 long double volatile resultl
;
41 /* Fetch the NaN values before we start watching out for FE_INVALID
42 exceptions, because the division 0.0 / 0.0 itself also raises an
44 The use of 'volatile' prevents the compiler from doing constant-folding
45 optimizations on these values. An alternative, for GCC only, would be
46 the command-line option '-fsignaling-nans'. */
47 float volatile nanf
= NaNf ();
48 double volatile nand
= NaNd ();
49 long double volatile nanl
= NaNl ();
51 /* Check that the values are really quiet. */
53 /* Clear FE_INVALID exceptions from past operations. */
54 feclearexcept (FE_INVALID
);
56 /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default
57 terminates the program. */
58 if (sigfpe_on_invalid () < 0)
60 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr
);
64 resultf
= nanf
+ 42.0f
;
65 resultd
= nand
+ 42.0;
66 resultl
= nanl
+ 42.0L;
68 return test_exit_status
;
73 /* No HAVE_FPE_TRAPPING available.
74 We could use the various alternative approaches from
75 libgfortran/config/fpu-*.h, but that's not worth it. */
80 fputs ("Skipping test: feenableexcept not available\n", stderr
);