[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
This commit is contained in:
Timo Kreuzer 2025-01-30 19:27:53 +02:00
parent 2fca81eca8
commit 736fea6c44
2 changed files with 23 additions and 1 deletions

View file

@ -57,7 +57,21 @@ typedef double double_t;
#define HUGE_VALD ((double)INFINITY)
#define HUGE_VALF ((float)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
#define NAN ((float)(INFINITY * 0.0F))
#ifndef _UCRT_NEGATIVE_NAN
// This operation creates a negative NAN adding a - to make it positive
#ifdef _MSC_VER
#define NAN (-(float)(INFINITY * 0.0F))
#else
#define NAN (__builtin_nanf(""))
#endif
#else
// Keep this for backwards compatibility
#ifdef _MSC_VER
#define NAN ((float)(INFINITY * 0.0F))
#else
#define NAN (-__builtin_nanf(""))
#endif
#endif
#define _DENORM (-2)
#define _FINITE (-1)

View file

@ -91,10 +91,18 @@ _CRT_BEGIN_C_HEADER
#define HUGE_VALL ((long double)INFINITY)
#ifndef _UCRT_NEGATIVE_NAN
// This operation creates a negative NAN adding a - to make it positive
#ifdef _MSC_VER
#define NAN (-(float)(INFINITY * 0.0F))
#else
#define NAN (__builtin_nanf(""))
#endif
#else
// Keep this for backwards compatibility
#ifdef _MSC_VER
#define NAN ((float)(INFINITY * 0.0F))
#else
#define NAN (-__builtin_nanf(""))
#endif
#endif
#define _DENORM (-2)