fixes #24772: system.NaN was negative when C (#24774)

fixes #24772

The old implementation was said to copied  from Windows SDK,

but you can find the newer SDK's definition is updated and the sign is
reversed compared to the old.


Also, `__builtin_nanf("")` is used if available,
which is more efficient than previous (In x86_64 gcc, latter produces
32B code but former just 8B).
This commit is contained in:
lit
2025-03-13 00:30:08 +08:00
committed by GitHub
parent dfa482e292
commit 4f32624641

View File

@@ -485,13 +485,22 @@ typedef char* NCSTRING;
#define paramCount() cmdCount
// NAN definition copied from math.h included in the Windows SDK version 10.0.14393.0
#ifndef NAN
#ifndef NAN /* use __builtin_nanf which is faster, if available */
# if defined(__GNUC__)
# define NAN (__builtin_nanf(""))
# elif defined(__clang__) /* XXX: writing __has_builtin this line cause MSVC complains. */
# if __has_builtin (__builtin_nanf)
# define NAN (__builtin_nanf(""))
# endif
# endif
#endif
#ifndef NAN /* modified from math.h included in the Windows SDK version 10.0.26100.0 */
# ifndef _HUGE_ENUF
# define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
# define _HUGE_ENUF 1e+300 /* _HUGE_ENUF*_HUGE_ENUF must overflow */
# endif
# define NAN_INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
# define NAN ((float)(NAN_INFINITY * 0.0F))
# define NAN (-(float)(NAN_INFINITY * 0.0F))
#endif
#ifndef INF