From 368d98ef9e9c4e9fc50bfbba250358a4f52369a8 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 25 Jul 2024 21:05:49 +0200 Subject: [PATCH] Add optional quiet param to KiRound --- libs/kimath/include/math/util.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/kimath/include/math/util.h b/libs/kimath/include/math/util.h index 705cc0b389..18858db553 100644 --- a/libs/kimath/include/math/util.h +++ b/libs/kimath/include/math/util.h @@ -97,20 +97,26 @@ inline constexpr ret_type KiCheckedCast( in_type v ) * In Debug build an assert fires if will not fit into the return type. */ template -constexpr ret_type KiROUND( fp_type v ) +constexpr ret_type KiROUND( fp_type v, bool aQuiet = false ) { using max_ret = long long int; fp_type ret = v < 0 ? v - 0.5 : v + 0.5; if( ret > std::numeric_limits::max() ) { - kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + if( !aQuiet ) + { + kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + } return std::numeric_limits::max() - 1; } else if( ret < std::numeric_limits::lowest() ) { - kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + if( !aQuiet ) + { + kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + } if( std::numeric_limits::is_signed ) return std::numeric_limits::lowest() + 1; @@ -122,7 +128,10 @@ constexpr ret_type KiROUND( fp_type v ) { if( std::isnan( v ) ) { - kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + if( !aQuiet ) + { + kimathLogOverflow( double( v ), typeid( ret_type ).name() ); + } return 0; }