diff options
author | Sophie Saskin <sophie.saskin@mongodb.com> | 2020-01-14 20:26:58 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-14 20:26:58 +0000 |
commit | a028f3c1888ecb35cd99435658f875b0963ed2f7 (patch) | |
tree | fd16ddf6d6eff743acb2ad3e2c1d5b7b9579825b /src/mongo | |
parent | e1b4db12bbe172da6381ff881305752faad1c740 (diff) | |
download | mongo-a028f3c1888ecb35cd99435658f875b0963ed2f7.tar.gz |
SERVER-45279 GranularityRounder rounding infinity case no longer causes infinite loop
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp index 35f520842c3..d99f640521c 100644 --- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp +++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp @@ -165,7 +165,7 @@ void uassertNonNegativeNumber(Value value) { Value GranularityRounderPreferredNumbers::roundUp(Value value) { uassertNonNegativeNumber(value); - if (value.coerceToDouble() == 0.0) { + if (value.coerceToDouble() == 0.0 || std::isinf(value.coerceToDouble())) { return value; } @@ -250,7 +250,7 @@ Value GranularityRounderPreferredNumbers::roundUp(Value value) { Value GranularityRounderPreferredNumbers::roundDown(Value value) { uassertNonNegativeNumber(value); - if (value.coerceToDouble() == 0.0) { + if (value.coerceToDouble() == 0.0 || std::isinf(value.coerceToDouble())) { return value; } diff --git a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp index e4d8600b404..0335b70a9d5 100644 --- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp +++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp @@ -528,5 +528,19 @@ TEST(GranularityRounderPreferredNumbersTest, ShouldFailOnRoundingNegativeNumber) ASSERT_THROWS_CODE(rounder->roundDown(negativeNumber), AssertionException, 40268); } } + +TEST(GranularityRounderPreferredNumbersTest, Infinity) { + auto rounder = + GranularityRounder::getGranularityRounder(new ExpressionContextForTest(), "E192"); + + Value inf = Value(std::numeric_limits<double>::infinity()); + ASSERT_TRUE(std::isinf(rounder->roundUp(inf).coerceToDouble())); + ASSERT_TRUE(std::isinf(rounder->roundDown(inf).coerceToDouble())); + + Value decimalInf = Value(Decimal128::kPositiveInfinity); + testEquals(rounder->roundUp(decimalInf), decimalInf); + testEquals(rounder->roundDown(decimalInf), decimalInf); +} + } // namespace } // namespace mongo |