summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2020-01-21 23:14:41 +0000
committerevergreen <evergreen@mongodb.com>2020-01-21 23:14:41 +0000
commit205777cb0f84ee2c1719203e15e82d67c11ba8b6 (patch)
tree6ed2aebf1d20e737d31a0ffe3d4d4295702629b3
parented78b6d54e794bddc99b9b9bc01c62cce22c9b56 (diff)
downloadmongo-205777cb0f84ee2c1719203e15e82d67c11ba8b6.tar.gz
SERVER-45279 GranularityRounder rounding infinity case no longer causes infinite loop
(cherry picked from commit a028f3c1888ecb35cd99435658f875b0963ed2f7)
-rw-r--r--src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp4
-rw-r--r--src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp14
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 b144b634f41..492adb19ebe 100644
--- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp
+++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers.cpp
@@ -166,7 +166,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;
}
@@ -251,7 +251,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 fca16828f29..f5768c58c9d 100644
--- a/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp
+++ b/src/mongo/db/pipeline/granularity_rounder_preferred_numbers_test.cpp
@@ -573,5 +573,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