From 21c279aab58fbbcb0692138987f367d56cff130f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 1 Dec 2022 12:07:32 +0200 Subject: [PATCH] crt-test: Skip the NAN preservation tests on platforms other than mingw This part of the tests does pass on glibc on x86_64 and on MSVC, but fails on macOS (for some functions) and on glibc on aarch64 (for one function). This is a somewhat overly pedantic test, but is useful for checking the NAN preservation behaviour when modifying implementations. Also print the sign bit explicitly - not all printf implementations distinguish between NAN and -NAN when printed. --- test/crt-test.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/crt-test.c b/test/crt-test.c index 6fdd383..465ca5e 100644 --- a/test/crt-test.c +++ b/test/crt-test.c @@ -86,6 +86,17 @@ const char *context = ""; } \ } while (0) +#if defined(__MINGW32__) || defined(TEST_NAN_PRESERVATION) +// Only check for NAN sign presevation on mingw (where the tests currently +// pass on all platforms and we want to keep checking that) or if +// TEST_NAN_PRESERVATION is defined. This aspect does fail for some +// functions on some libcs - but ignore those failures as it's a rather +// overly pedantic test. +#define NAN_MATCHING_SIGNS(a, b) (!!signbit(a) == !!signbit(b)) +#else +#define NAN_MATCHING_SIGNS(a, b) (1) +#endif + // Use TEST_FLT_NAN with F(NAN) or -F(NAN) as the expect parameter. // On Glibc, F(-NAN), i.e. strtod("-NAN", NULL), returns a positive NAN. // On MSVC, the NAN literal is negative, but strtod("NAN", NULL) returns a @@ -94,9 +105,9 @@ const char *context = ""; tests++; \ long double val = (x); \ long double expval = (expect); \ - if (!isnan(val) || !!signbit(val) != !!signbit(expval)) { \ + if (!isnan(val) || !NAN_MATCHING_SIGNS(val, expval)) { \ fails++; \ - printf("%s:%d: %s%s failed, expected %f, got %f\n", __FILE__, __LINE__, context, #x, (double)expval, (double)val); \ + printf("%s:%d: %s%s failed, expected %f (sign %d), got %f (sign %d)\n", __FILE__, __LINE__, context, #x, (double)expval, signbit(expval), (double)val, signbit(val)); \ } \ } while (0)