From 99e6df4612ac596da6413112223e1867f6c8b5af Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 17 Jan 2016 16:58:47 +1100 Subject: [PATCH] [Common] Add fesetround to Platform.cpp --- Source/Common/Platform.cpp | 19 +++++++++++++++++-- Source/Common/Platform.h | 11 ++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Source/Common/Platform.cpp b/Source/Common/Platform.cpp index 845f09642..26ee3f3e4 100644 --- a/Source/Common/Platform.cpp +++ b/Source/Common/Platform.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #ifndef _WIN32 -int _vscprintf (const char * format, va_list pargs) +int _vscprintf(const char * format, va_list pargs) { int retval; va_list argcopy; @@ -10,4 +10,19 @@ int _vscprintf (const char * format, va_list pargs) va_end(argcopy); return retval; } -#endif \ No newline at end of file +#endif + +#ifdef _MSC_VER +#include + +int fesetround(int RoundType) +{ + static const unsigned int msRound[4] = { _RC_NEAR, _RC_CHOP, _RC_UP, _RC_DOWN }; + int32_t res = _controlfp(msRound[RoundType], _MCW_RC); + if (res == _RC_NEAR) { return FE_TONEAREST; } + if (res == _RC_CHOP) { return FE_TOWARDZERO; } + if (res == _RC_UP) { return FE_UPWARD; } + if (res == _RC_DOWN) { return FE_DOWNWARD; } + return FE_TONEAREST; +} +#endif diff --git a/Source/Common/Platform.h b/Source/Common/Platform.h index 8fd411564..5757a41b9 100644 --- a/Source/Common/Platform.h +++ b/Source/Common/Platform.h @@ -7,8 +7,17 @@ #define _stricmp strcasecmp #define _strnicmp strncasecmp #define _snprintf snprintf +#define _isnan isnan #define GetCurrentThreadId pthread_self int _vscprintf (const char * format, va_list pargs); -#endif \ No newline at end of file +#endif + +//FPU rounding code +#ifdef _WIN32 +typedef enum { FE_TONEAREST = 0, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD } eRoundType; +int fesetround(int RoundType); +#else +#include +#endif