Skip to content

Commit

Permalink
revert Fix half up in round
Browse files Browse the repository at this point in the history
  • Loading branch information
JkSelf committed Jun 28, 2023
1 parent a82efbb commit f332360
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 8 additions & 0 deletions velox/expression/tests/ExprTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,14 @@ TEST_F(ExprTest, shortCircuit) {
assertEqualVectors(expectedResult, result);
}

TEST_F(ExprTest, round) {
vector_size_t size = 4;
auto a = makeConstant(-1.0249999999999999, size);
auto result = evaluate("round(c0, cast (3 as int))", makeRowVector({a}));
auto expectedResult = makeConstant(-1.025, size);
assertEqualVectors(expectedResult, result);
}

// Test common sub-expression (CSE) optimization with encodings.
// CSE evaluation may happen in different contexts, e.g. original input rows
// on first evaluation and base vectors uncovered through peeling of encodings
Expand Down
9 changes: 2 additions & 7 deletions velox/functions/prestosql/ArithmeticImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ round(const TNum& number, const TDecimals& decimals = 0) {
}

double factor = std::pow(10, decimals);
double variance = 0.1;
if (number < 0) {
return (std::round(
std::nextafter(number, number - variance) * factor * -1) /
factor) *
-1;
return (std::round(number * factor * -1) / factor) * -1;
}
return std::round(std::nextafter(number, number + variance) * factor) /
factor;
return std::round(number * factor) / factor;
}

// This is used by Velox for floating points plus.
Expand Down

0 comments on commit f332360

Please sign in to comment.