Skip to content

Commit 736fea6

Browse files
committed
[CRT] math.h: fix definition of NAN
- Use positive NAN by default - add support for _UCRT_NEGATIVE_NAN to legacy CRT headers - Use __builtin_nanf() on GCC/Clang
1 parent 2fca81e commit 736fea6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sdk/include/crt/math.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@ typedef double double_t;
5757
#define HUGE_VALD ((double)INFINITY)
5858
#define HUGE_VALF ((float)INFINITY)
5959
#define HUGE_VALL ((long double)INFINITY)
60-
#define NAN ((float)(INFINITY * 0.0F))
60+
#ifndef _UCRT_NEGATIVE_NAN
61+
// This operation creates a negative NAN adding a - to make it positive
62+
#ifdef _MSC_VER
63+
#define NAN (-(float)(INFINITY * 0.0F))
64+
#else
65+
#define NAN (__builtin_nanf(""))
66+
#endif
67+
#else
68+
// Keep this for backwards compatibility
69+
#ifdef _MSC_VER
70+
#define NAN ((float)(INFINITY * 0.0F))
71+
#else
72+
#define NAN (-__builtin_nanf(""))
73+
#endif
74+
#endif
6175

6276
#define _DENORM (-2)
6377
#define _FINITE (-1)

sdk/include/ucrt/corecrt_math.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@ _CRT_BEGIN_C_HEADER
9191
#define HUGE_VALL ((long double)INFINITY)
9292
#ifndef _UCRT_NEGATIVE_NAN
9393
// This operation creates a negative NAN adding a - to make it positive
94+
#ifdef _MSC_VER
9495
#define NAN (-(float)(INFINITY * 0.0F))
9596
#else
97+
#define NAN (__builtin_nanf(""))
98+
#endif
99+
#else
96100
// Keep this for backwards compatibility
101+
#ifdef _MSC_VER
97102
#define NAN ((float)(INFINITY * 0.0F))
103+
#else
104+
#define NAN (-__builtin_nanf(""))
105+
#endif
98106
#endif
99107

100108
#define _DENORM (-2)

0 commit comments

Comments
 (0)