Standardize rounding in 64-bit rescale
32-bit rescale still uses truncation until we can determine how this affects poly_grid_partition
This commit is contained in:
parent
77acf85310
commit
a342bb9ab3
|
@ -31,15 +31,21 @@
|
||||||
template<>
|
template<>
|
||||||
int rescale( int aNumerator, int aValue, int aDenominator )
|
int rescale( int aNumerator, int aValue, int aDenominator )
|
||||||
{
|
{
|
||||||
return (int) ( (int64_t) aNumerator * (int64_t) aValue / (int64_t) aDenominator );
|
int64_t numerator = (int64_t) aNumerator * (int64_t) aValue;
|
||||||
|
return numerator / aDenominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )
|
int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )
|
||||||
{
|
{
|
||||||
#ifdef __x86_64__
|
#ifdef __SIZEOF_INT128__
|
||||||
return ( (__int128_t) aNumerator * (__int128_t) aValue ) / aDenominator;
|
__int128_t numerator = (__int128_t) aNumerator * (__int128_t) aValue;
|
||||||
|
|
||||||
|
if( ( numerator < 0 ) ^ ( aDenominator < 0 ) )
|
||||||
|
return ( numerator - aDenominator / 2 ) / aDenominator;
|
||||||
|
else
|
||||||
|
return ( numerator + aDenominator / 2 ) / aDenominator;
|
||||||
#else
|
#else
|
||||||
int64_t r = 0;
|
int64_t r = 0;
|
||||||
int64_t sign = ( ( aNumerator < 0 ) ? -1 : 1 ) * ( aDenominator < 0 ? -1 : 1 ) *
|
int64_t sign = ( ( aNumerator < 0 ) ? -1 : 1 ) * ( aDenominator < 0 ? -1 : 1 ) *
|
||||||
|
|
Loading…
Reference in New Issue