39void kimathLogDebug(
const char* aFormatString, ... );
52template <
typename T>
inline const T& Clamp(
const T& lower,
const T& value,
const T& upper )
56 else if( upper < value )
62#ifdef HAVE_WIMPLICIT_FLOAT_CONVERSION
63 _Pragma(
"GCC diagnostic push" ) \
64 _Pragma(
"GCC diagnostic ignored \"-Wimplicit-int-float-conversion\"" )
72template <
typename fp_type,
typename ret_type =
int>
73constexpr ret_type KiROUND( fp_type v )
75 using max_ret =
long long int;
76 fp_type ret = v < 0 ? v - 0.5 : v + 0.5;
78 if( std::numeric_limits<ret_type>::max() < ret ||
79 std::numeric_limits<ret_type>::lowest() > ret )
81 kimathLogDebug(
"Overflow KiROUND converting value %f to %s",
double( v ),
82 typeid( ret_type ).name() );
86 return ret_type( max_ret( ret ) );
89#ifdef HAVE_WIMPLICIT_FLOAT_CONVERSION
90 _Pragma(
"GCC diagnostic pop" )
98T rescale( T aNumerator, T aValue, T aDenominator )
100 return aNumerator * aValue / aDenominator;
106 return ( T( 0 ) < val) - ( val < T( 0 ) );
111int rescale(
int aNumerator,
int aValue,
int aDenominator );
114int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator );