[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

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#ifndef _WIN32 #ifndef _WIN32
int _vscprintf (const char * format, va_list pargs) int _vscprintf(const char * format, va_list pargs)
{ {
int retval; int retval;
va_list argcopy; va_list argcopy;
@ -10,4 +10,19 @@ int _vscprintf (const char * format, va_list pargs)
va_end(argcopy); va_end(argcopy);
return retval; return retval;
} }
#endif #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 _stricmp strcasecmp
#define _strnicmp strncasecmp #define _strnicmp strncasecmp
#define _snprintf snprintf #define _snprintf snprintf
#define _isnan isnan
#define GetCurrentThreadId pthread_self #define GetCurrentThreadId pthread_self
int _vscprintf (const char * format, va_list pargs); int _vscprintf (const char * format, va_list pargs);
#endif #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