diff --git a/dbms/src/Functions/FunctionsRound.h b/dbms/src/Functions/FunctionsRound.h index 9872cdac676..4ba3a9d24db 100644 --- a/dbms/src/Functions/FunctionsRound.h +++ b/dbms/src/Functions/FunctionsRound.h @@ -119,11 +119,11 @@ struct IntegerRoundingComputation } case RoundingMode::Round: { + if (x < 0) + x -= scale; switch (tie_breaking_mode) { case TieBreakingMode::Auto: - if (x < 0) - x -= scale; x = (x + scale / 2) / scale * scale; break; case TieBreakingMode::Bankers: @@ -131,14 +131,10 @@ struct IntegerRoundingComputation T quotient = (x + scale / 2) / scale; if (quotient * scale == x + scale / 2) // round half to even - x = (quotient & ~1) * scale; + x = ((quotient + (x < 0)) & ~1) * scale; else - { // round the others as usual - if (x < 0) - quotient -= 1; x = quotient * scale; - } break; } }