From 35e639c5999c2740917e49a00ecb665ef6072db8 Mon Sep 17 00:00:00 2001 From: "tomasz.wlostowski@cern.ch" Date: Mon, 9 Sep 2013 16:55:01 +0200 Subject: [PATCH] math/math_util.h: fixed signedness bug in rescale() --- include/math/math_util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/math/math_util.h b/include/math/math_util.h index 2a3ff3fa17..9145b7fa89 100644 --- a/include/math/math_util.h +++ b/include/math/math_util.h @@ -50,12 +50,12 @@ template<> int rescale( int numerator, int value, int denominator ) template<> int64_t rescale( int64_t numerator, int64_t value, int64_t denominator ) { - uint64_t r = 0; + int64_t r = 0; int64_t sign = ( ( numerator < 0) ? -1 : 1 ) * ( denominator < 0 ? - 1: 1 ) * (value < 0 ? - 1 : 1); - uint64_t a = abs( numerator ); - uint64_t b = abs( value ); - uint64_t c = abs( denominator ); + int64_t a = std::abs( numerator ); + int64_t b = std::abs( value ); + int64_t c = std::abs( denominator ); r = c / 2; @@ -77,14 +77,14 @@ template<> int64_t rescale( int64_t numerator, int64_t value, int64_t denominato a0 = a0 * b0 + t1a; a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a); a0 += r; - a1 += a0 < r; + a1 += ((uint64_t)a0) < r; for( i = 63; i >= 0; i-- ) { a1 += a1 + ( (a0 >> i) & 1 ); t1 += t1; - if( c <= a1 ) + if( (uint64_t)c <= a1 ) { a1 -= c; t1++;