summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/pipeline/expression.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 51c0275efba..5a26f521ab8 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -2704,11 +2704,17 @@ Value ExpressionMultiply::evaluate(const Document& root, Variables* variables) c
decimalProduct = decimalProduct.multiply(val.coerceToDecimal());
} else {
doubleProduct *= val.coerceToDouble();
- if (!std::isfinite(val.coerceToDouble()) ||
- mongoSignedMultiplyOverflow64(longProduct, val.coerceToLong(), &longProduct)) {
- // The number is either Infinity or NaN, or the 'longProduct' would have
- // overflowed, so we're abandoning it.
- productType = NumberDouble;
+
+ if (productType != NumberDouble) {
+ // If `productType` is not a double, it must be one of the integer types, so we
+ // attempt to update `longProduct`.
+ if (!std::isfinite(val.coerceToDouble()) ||
+ mongoSignedMultiplyOverflow64(
+ longProduct, val.coerceToLong(), &longProduct)) {
+ // The number is either Infinity or NaN, or the 'longProduct' would have
+ // overflowed, so we're abandoning it.
+ productType = NumberDouble;
+ }
}
}
} else if (val.nullish()) {