Skip to content

Commit 4f32624

Browse files
authored
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).
1 parent dfa482e commit 4f32624

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/nimbase.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,22 @@ typedef char* NCSTRING;
485485

486486
#define paramCount() cmdCount
487487

488-
// NAN definition copied from math.h included in the Windows SDK version 10.0.14393.0
489-
#ifndef NAN
488+
#ifndef NAN /* use __builtin_nanf which is faster, if available */
489+
# if defined(__GNUC__)
490+
# define NAN (__builtin_nanf(""))
491+
# elif defined(__clang__) /* XXX: writing __has_builtin this line cause MSVC complains. */
492+
# if __has_builtin (__builtin_nanf)
493+
# define NAN (__builtin_nanf(""))
494+
# endif
495+
# endif
496+
#endif
497+
498+
#ifndef NAN /* modified from math.h included in the Windows SDK version 10.0.26100.0 */
490499
# ifndef _HUGE_ENUF
491-
# define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
500+
# define _HUGE_ENUF 1e+300 /* _HUGE_ENUF*_HUGE_ENUF must overflow */
492501
# endif
493502
# define NAN_INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
494-
# define NAN ((float)(NAN_INFINITY * 0.0F))
503+
# define NAN (-(float)(NAN_INFINITY * 0.0F))
495504
#endif
496505

497506
#ifndef INF

0 commit comments

Comments
 (0)