Skip to content

Commit c19bda6

Browse files
authored
Fix half up in round (#95)
1 parent ec13460 commit c19bda6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

velox/functions/prestosql/ArithmeticImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ round(const TNum& number, const TDecimals& decimals = 0) {
4343
}
4444

4545
double factor = std::pow(10, decimals);
46+
double variance = 0.1;
4647
if (number < 0) {
47-
return (std::round(number * factor * -1) / factor) * -1;
48+
return (std::round(std::nextafter(number, number - variance) * factor * -1) / factor) * -1;
4849
}
49-
return std::round(number * factor) / factor;
50+
return std::round(std::nextafter(number, number + variance) * factor) / factor;
5051
}
5152

5253
// This is used by Velox for floating points plus.

0 commit comments

Comments
 (0)