Skip to content

Commit

Permalink
Fix isFinite for NaN input
Browse files Browse the repository at this point in the history
Summary: isFinite() currently incorrectly classifies NaN as finite. This fixes that bug.

Reviewed By: amitkdutta

Differential Revision: D60204120
  • Loading branch information
Bikramjeet Vig authored and facebook-github-bot committed Jul 24, 2024
1 parent 82bde6d commit dbcbc42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/functions/prestosql/Arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ struct InfinityFunction {
template <typename T>
struct IsFiniteFunction {
FOLLY_ALWAYS_INLINE void call(bool& result, double a) {
result = !std::isinf(a);
result = std::isfinite(a);
}
};

Expand Down
2 changes: 2 additions & 0 deletions velox/functions/prestosql/tests/ArithmeticTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ TEST_F(ArithmeticTest, isFinite) {
EXPECT_EQ(false, isFinite(-kInf));
EXPECT_EQ(false, isFinite(1.0 / 0.0));
EXPECT_EQ(false, isFinite(-1.0 / 0.0));
EXPECT_EQ(false, isFinite(kNan));
}

TEST_F(ArithmeticTest, isInfinite) {
Expand All @@ -607,6 +608,7 @@ TEST_F(ArithmeticTest, isInfinite) {
};

EXPECT_EQ(false, isInfinite(0.0));
EXPECT_EQ(false, isInfinite(kNan));
EXPECT_EQ(true, isInfinite(kInf));
EXPECT_EQ(true, isInfinite(-kInf));
EXPECT_EQ(true, isInfinite(1.0 / 0.0));
Expand Down

0 comments on commit dbcbc42

Please sign in to comment.