[Common] Add fesetround to Platform.cpp

This commit is contained in:
zilmar 2016-01-17 16:58:47 +11:00
parent 554333711f
commit 99e6df4612
2 changed files with 27 additions and 3 deletions

View File

@ -11,3 +11,18 @@ int _vscprintf (const char * format, va_list pargs)
return retval;
}
#endif
#ifdef _MSC_VER
#include <float.h>
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

View File

@ -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
//FPU rounding code
#ifdef _WIN32
typedef enum { FE_TONEAREST = 0, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD } eRoundType;
int fesetround(int RoundType);
#else
#include <fenv.h>
#endif