usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-nan-1.c
blob70e9b6d63c26797580c1cdfe6209e41f94bc1034
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. */
19 #include <config.h>
21 /* Specification. */
22 #include "nan.h"
24 #if defined __GLIBC__ && defined __arm__ && defined __SOFTFP__
26 # include <stdio.h>
28 /* The arm software floating-point emulation (used e.g. on armv5) does not set
29 the floating-point exception bits. */
31 int
32 main ()
34 fputs ("Skipping test: software floating-point emulation\n", stderr);
35 return 77;
38 #else
40 # include <fenv.h>
42 # include "macros.h"
44 float volatile resultf;
45 double volatile resultd;
46 long double volatile resultl;
48 int
49 main ()
51 /* Fetch the NaN values before we start watching out for FE_INVALID
52 exceptions, because the division 0.0 / 0.0 itself also raises an
53 FE_INVALID exception.
54 The use of 'volatile' prevents the compiler from doing constant-folding
55 optimizations on these values. An alternative, for GCC only, would be
56 the command-line option '-fsignaling-nans'. */
57 float volatile nanf = NaNf ();
58 double volatile nand = NaNd ();
59 long double volatile nanl = NaNl ();
61 /* Check that the values are really quiet. */
63 feclearexcept (FE_INVALID);
64 resultf = nanf + 42.0f;
65 ASSERT (!fetestexcept (FE_INVALID));
68 feclearexcept (FE_INVALID);
69 resultd = nand + 42.0;
70 ASSERT (!fetestexcept (FE_INVALID));
73 feclearexcept (FE_INVALID);
74 resultl = nanl + 42.0L;
75 ASSERT (!fetestexcept (FE_INVALID));
78 return test_exit_status;
81 #endif