diff --git a/source/common/thirdparty/xs_Float.h b/source/common/thirdparty/xs_Float.h index 6c676ee3a..d687e2dcb 100644 --- a/source/common/thirdparty/xs_Float.h +++ b/source/common/thirdparty/xs_Float.h @@ -42,10 +42,15 @@ typedef double real64; -union _xs_doubleints +struct _xs_doubleints { - real64 val; - uint32_t ival[2]; + union + { + real64 val; + uint32_t ival[2]; + }; + + constexpr _xs_doubleints(real64 v) : val(v) {} }; #if 0 @@ -56,73 +61,9 @@ union _xs_doubleints // ==================================================================================================================== // Constants // ==================================================================================================================== -const real64 _xs_doublemagic = real64 (6755399441055744.0); //2^52 * 1.5, uses limited precisicion to floor -const real64 _xs_doublemagicdelta = (1.5e-8); //almost .5f = .5f + 1e^(number of exp bit) -const real64 _xs_doublemagicroundeps = (.5f-_xs_doublemagicdelta); //almost .5f = .5f - 1e^(number of exp bit) - - -// ==================================================================================================================== -// Prototypes -// ==================================================================================================================== -static int32_t xs_CRoundToInt (real64 val, real64 dmr = _xs_doublemagic); -static int32_t xs_ToInt (real64 val, real64 dme = -_xs_doublemagicroundeps); -static int32_t xs_FloorToInt (real64 val, real64 dme = _xs_doublemagicroundeps); -static int32_t xs_CeilToInt (real64 val, real64 dme = _xs_doublemagicroundeps); -static int32_t xs_RoundToInt (real64 val); - -//int32_t versions -finline static int32_t xs_CRoundToInt (int32_t val) {return val;} -finline static int32_t xs_ToInt (int32_t val) {return val;} - - - -// ==================================================================================================================== -// Fix Class -// ==================================================================================================================== -template class xs_Fix -{ -public: - typedef int32_t Fix; - - // ==================================================================================================================== - // Basic Conversion from Numbers - // ==================================================================================================================== - finline static Fix ToFix (int32_t val) {return val<>N;} - - - -protected: - // ==================================================================================================================== - // Helper function - mainly to preserve _xs_DEFAULT_CONVERSION - // ==================================================================================================================== - finline static int32_t xs_ConvertToFixed (real64 val) - { - #if _xs_DEFAULT_CONVERSION==0 - return xs_CRoundToInt(val, _xs_doublemagic/(1< class xs_Fix +{ +public: + typedef int32_t Fix; + + // ==================================================================================================================== + // Basic Conversion from Numbers + // ==================================================================================================================== + finline static constexpr Fix ToFix (int32_t val) {return val<>N;} + + + +protected: + // ==================================================================================================================== + // Helper function - mainly to preserve _xs_DEFAULT_CONVERSION + // ==================================================================================================================== + finline static constexpr int32_t xs_ConvertToFixed (real64 val) + { + #if _xs_DEFAULT_CONVERSION==0 + return xs_CRoundToInt(val, _xs_doublemagic/(1<