diff --git a/common/math/math_util.cpp b/common/math/math_util.cpp index d3f69e81a7..81dafc3a74 100644 --- a/common/math/math_util.cpp +++ b/common/math/math_util.cpp @@ -27,20 +27,24 @@ #include #include #include +#include -template <> +template<> int rescale( int aNumerator, int aValue, int aDenominator ) { return (int) ( (int64_t) aNumerator * (int64_t) aValue / (int64_t) aDenominator ); } -template <> +template<> int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator ) { +#ifdef __x86_64__ + return ( (__int128_t) aNumerator * (__int128_t) aValue ) / aDenominator; +#else int64_t r = 0; int64_t sign = ( ( aNumerator < 0 ) ? -1 : 1 ) * ( aDenominator < 0 ? -1 : 1 ) * - ( aValue < 0 ? -1 : 1 ); + ( aValue < 0 ? -1 : 1 ); int64_t a = std::abs( aNumerator ); int64_t b = std::abs( aValue ); @@ -84,4 +88,5 @@ int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator ) return t1 * sign; } +#endif }