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.
This commit is contained in:
Martin Storsjö committed 2022-12-01 12:07:32 +02:00
1 parent 6a37ec900b
commit 21c279aab5
1 file changed
+13 -2
+13 -2
View File
@@ -86,6 +86,17 @@ const char *context = "";
} \ } \
} while (0) } 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. // 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 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 // On MSVC, the NAN literal is negative, but strtod("NAN", NULL) returns a
@@ -94,9 +105,9 @@ const char *context = "";
tests++; \ tests++; \
long double val = (x); \ long double val = (x); \
long double expval = (expect); \ long double expval = (expect); \
if (!isnan(val) || !!signbit(val) != !!signbit(expval)) { \ if (!isnan(val) || !NAN_MATCHING_SIGNS(val, expval)) { \
fails++; \ 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) } while (0)