From a16ef96dc624edf2666aa125fbc1c197f5edcc1b Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 30 May 2019 09:09:59 +0200 Subject: [PATCH] include/msvcrt: Add INFINITY and NAN definitions. Signed-off-by: Alexandre Julliard --- dlls/d3dx9_36/tests/effect.c | 19 ------------------- dlls/msvcirt/tests/msvcirt.c | 15 +-------------- dlls/msvcp120/tests/msvcp120.c | 14 -------------- dlls/msvcp90/tests/misc.c | 14 -------------- dlls/msvcr120/tests/msvcr120.c | 25 +------------------------ dlls/msvcrt/tests/misc.c | 14 -------------- dlls/msvcrt/tests/printf.c | 17 ++--------------- dlls/ucrtbase/tests/misc.c | 15 +-------------- dlls/ucrtbase/tests/printf.c | 15 +-------------- dlls/ucrtbase/tests/string.c | 18 ------------------ dlls/webservices/tests/writer.c | 20 +------------------- include/msvcrt/math.h | 12 ++++++++++++ include/wine/test.h | 9 +++++++++ 13 files changed, 28 insertions(+), 179 deletions(-) diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c index c10decc5c2d..5c4a3c5e770 100644 --- a/dlls/d3dx9_36/tests/effect.c +++ b/dlls/d3dx9_36/tests/effect.c @@ -22,25 +22,6 @@ #include "wine/test.h" #include "d3dx9.h" -#ifndef INFINITY -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() -#endif /* INFINITY */ - -#ifndef NAN -static float get_nan(void) -{ - DWORD nan = 0x7fc00000; - - return *(float *)&nan; -} -#define NAN get_nan() -#endif - /* helper functions */ static BOOL compare_float(FLOAT f, FLOAT g, UINT ulps) { diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index c856b50a418..2cdd10d279c 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -180,20 +181,6 @@ typedef struct { exception e; } logic_error; -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - #undef __thiscall #ifdef __i386__ #define __thiscall __stdcall diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c index c416a1020b7..8f7b75aab4b 100644 --- a/dlls/msvcp120/tests/msvcp120.c +++ b/dlls/msvcp120/tests/msvcp120.c @@ -169,20 +169,6 @@ static void init_thiscall_thunk(void) #define call_func7(func,_this,a,b,c,d,e,f) func(_this,a,b,c,d,e,f) #endif /* __i386__ */ -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - typedef int MSVCRT_long; typedef unsigned char MSVCP_bool; diff --git a/dlls/msvcp90/tests/misc.c b/dlls/msvcp90/tests/misc.c index e9fd1e06be7..34a533a0a54 100644 --- a/dlls/msvcp90/tests/misc.c +++ b/dlls/msvcp90/tests/misc.c @@ -27,20 +27,6 @@ #include #include "wine/test.h" -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - static inline float __port_ind(void) { static const unsigned __ind_bytes = 0xffc00000; diff --git a/dlls/msvcr120/tests/msvcr120.c b/dlls/msvcr120/tests/msvcr120.c index be5df27e937..a055feeac91 100644 --- a/dlls/msvcr120/tests/msvcr120.c +++ b/dlls/msvcr120/tests/msvcr120.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -114,30 +115,6 @@ typedef struct { critical_section lock; } _Condition_variable; -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - -static inline int isnormal(double d) -{ - return _fpclass(d) & (_FPCLASS_PN | _FPCLASS_NN); -} - -static inline int isinf(double d) -{ - return _fpclass(d) & (_FPCLASS_PINF | _FPCLASS_NINF); -} - struct MSVCRT_lconv { char* decimal_point; diff --git a/dlls/msvcrt/tests/misc.c b/dlls/msvcrt/tests/misc.c index c170d232250..c59464f82d6 100644 --- a/dlls/msvcrt/tests/misc.c +++ b/dlls/msvcrt/tests/misc.c @@ -25,20 +25,6 @@ #include "msvcrt.h" #include -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - static inline BOOL almost_equal(double d1, double d2) { if(d1-d2>-1e-30 && d1-d2<1e-30) return TRUE; diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index ad55e4f604b..5e15989d1cf 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -24,9 +24,10 @@ * the following macro is defined. */ #define _CRT_NON_CONFORMING_SWPRINTFS - + #include #include +#include #include #include "windef.h" @@ -35,20 +36,6 @@ #include "wine/test.h" -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - static inline float __port_ind(void) { static const unsigned __ind_bytes = 0xffc00000; diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index 7559edecc33..4da6abff73e 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -57,20 +58,6 @@ expect_ ## func = called_ ## func = FALSE; \ }while(0) -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - static inline double __port_min_pos_double(void) { static const UINT64 __min_pos_double = 0x10000000000000; diff --git a/dlls/ucrtbase/tests/printf.c b/dlls/ucrtbase/tests/printf.c index 41bb6a335ed..769121ebd98 100644 --- a/dlls/ucrtbase/tests/printf.c +++ b/dlls/ucrtbase/tests/printf.c @@ -23,6 +23,7 @@ #include #include +#include #include "windef.h" #include "winbase.h" @@ -66,20 +67,6 @@ DEFINE_EXPECT(invalid_parameter_handler); #define UCRTBASE_PRINTF_LEGACY_MSVCRT_COMPATIBILITY (0x0008) #define UCRTBASE_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS (0x0010) -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() - -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() - static inline float __port_ind(void) { static const unsigned __ind_bytes = 0xffc00000; diff --git a/dlls/ucrtbase/tests/string.c b/dlls/ucrtbase/tests/string.c index 38aa6b3fa3c..e96843125e6 100644 --- a/dlls/ucrtbase/tests/string.c +++ b/dlls/ucrtbase/tests/string.c @@ -57,24 +57,6 @@ DEFINE_EXPECT(invalid_parameter_handler); static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler); -#ifndef INFINITY -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() -#endif - -#ifndef NAN -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() -#endif - static void __cdecl test_invalid_parameter_handler(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned line, uintptr_t arg) diff --git a/dlls/webservices/tests/writer.c b/dlls/webservices/tests/writer.c index 8d189fd9e4e..905f397b64b 100644 --- a/dlls/webservices/tests/writer.c +++ b/dlls/webservices/tests/writer.c @@ -17,30 +17,12 @@ */ #include +#include #include "windows.h" #include "rpc.h" #include "webservices.h" #include "wine/test.h" -#include -#ifndef INFINITY -static inline float __port_infinity(void) -{ - static const unsigned __inf_bytes = 0x7f800000; - return *(const float *)&__inf_bytes; -} -#define INFINITY __port_infinity() -#endif - -#ifndef NAN -static inline float __port_nan(void) -{ - static const unsigned __nan_bytes = 0x7fc00000; - return *(const float *)&__nan_bytes; -} -#define NAN __port_nan() -#endif - static HRESULT set_output( WS_XML_WRITER *writer ) { WS_XML_WRITER_TEXT_ENCODING text = { {WS_XML_WRITER_ENCODING_TYPE_TEXT}, WS_CHARSET_UTF8 }; diff --git a/include/msvcrt/math.h b/include/msvcrt/math.h index b82961e817c..e85767926f4 100644 --- a/include/msvcrt/math.h +++ b/include/msvcrt/math.h @@ -205,6 +205,18 @@ static const union { # endif #endif +#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))) +# define INFINITY __builtin_inff() +# define NAN __builtin_nanf("") +#else +static const union { + unsigned int __i; + float __f; +} __inff = { 0x7f800000 }, __nanf = { 0x7fc00000 }; +# define INFINITY (__inff.__f) +# define NAN (__nanf.__f) +#endif + #define FP_INFINITE 1 #define FP_NAN 2 #define FP_NORMAL -1 diff --git a/include/wine/test.h b/include/wine/test.h index 0797204a50e..b5aa9c14c70 100644 --- a/include/wine/test.h +++ b/include/wine/test.h @@ -46,6 +46,15 @@ #define INVALID_SET_FILE_POINTER (~0u) #endif +#ifdef _MSC_VER +# ifndef INFINITY +# define INFINITY ((float)HUGE_VAL) +# endif +# ifndef NAN +# define NAN (INFINITY * 0.0f) +# endif +#endif + /* debug level */ extern int winetest_debug;