usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-snan-1.c
blob8fb41fa6d6fd647a1a7db5c86f87c6eb5d0ebdf2
1 /* Tests of signalling 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 "snan.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 _GL_UNUSED float volatile nanf = SNaNf ();
58 _GL_UNUSED double volatile nand = SNaNd ();
59 _GL_UNUSED long double volatile nanl = SNaNl ();
61 /* Check that the values are really signalling. */
62 /* These tests do not work on 32-bit x86 processors, as well as
63 on x86_64 processors with CC="gcc -mfpmath=387", because loading SNaNf()
64 or SNaNd() into a 387 FPU register already converted it to a quiet NaN.
65 See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
66 for details. */
67 #if !((defined __i386 || defined _M_IX86) \
68 || ((defined __x86_64__ || defined _M_X64) && __FLT_EVAL_METHOD__ == 2))
69 /* This test does not work on AIX 7.1 with the xlc compiler, even with
70 the compiler options -qfloat=fenv -qfloat=nans -qfloat=spnans. */
71 #if !(defined _AIX && defined __xlC__)
73 feclearexcept (FE_INVALID);
74 resultf = nanf + 42.0f;
75 ASSERT (fetestexcept (FE_INVALID));
77 #endif
79 feclearexcept (FE_INVALID);
80 resultd = nand + 42.0;
81 ASSERT (fetestexcept (FE_INVALID));
83 #endif
84 /* This test does not work on eglibc 2.13/mips64
85 (bug in libc function __addtf3).
86 This test does not work on FreeBSD/arm64 and OpenBSD/mips64
87 (bug in libc function __addtf3).
88 This test does not work on FreeBSD/sparc64 and NetBSD/sparc64
89 (bug in libc function _Qp_add).
90 This test does not work on MSVC/i386, because of the general IA-32
91 problem (see above) and 'long double' == 'double'. */
92 #if !((((__GLIBC__ == 2 && __GLIBC_MINOR__ < 19 && defined __mips64) \
93 || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __mips64__ || defined __sparc__))) \
94 && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \
95 || ((defined __i386 || defined _M_IX86) && HAVE_SAME_LONG_DOUBLE_AS_DOUBLE))
97 feclearexcept (FE_INVALID);
98 resultl = nanl + 42.0L;
99 ASSERT (fetestexcept (FE_INVALID));
101 #endif
103 return test_exit_status;
106 #endif