Skip to content

Commit e3ea169

Browse files
committed
revert Fix half up in round
1 parent bb35ed6 commit e3ea169

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

velox/expression/tests/ExprTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,14 @@ TEST_F(ExprTest, shortCircuit) {
839839
assertEqualVectors(expectedResult, result);
840840
}
841841

842+
TEST_F(ExprTest, round) {
843+
vector_size_t size = 4;
844+
auto a = makeConstant(-1.0249999999999999, size);
845+
auto result = evaluate("round(c0, cast (3 as int))", makeRowVector({a}));
846+
auto expectedResult = makeConstant(-1.025, size);
847+
assertEqualVectors(expectedResult, result);
848+
}
849+
842850
// Test common sub-expression (CSE) optimization with encodings.
843851
// CSE evaluation may happen in different contexts, e.g. original input rows
844852
// on first evaluation and base vectors uncovered through peeling of encodings

velox/functions/prestosql/ArithmeticImpl.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ round(const TNum& number, const TDecimals& decimals = 0) {
4444
}
4545

4646
double factor = std::pow(10, decimals);
47-
double variance = 0.1;
4847
if (number < 0) {
49-
return (std::round(
50-
std::nextafter(number, number - variance) * factor * -1) /
51-
factor) *
52-
-1;
48+
return (std::round(number * factor * -1) / factor) * -1;
5349
}
54-
return std::round(std::nextafter(number, number + variance) * factor) /
55-
factor;
50+
return std::round(number * factor) / factor;
5651
}
5752

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

0 commit comments

Comments
 (0)