diff options
-rw-r--r-- | src/mongo/bson/bson_obj_test.cpp | 289 | ||||
-rw-r--r-- | src/mongo/bson/bson_validate.cpp | 2 | ||||
-rw-r--r-- | src/mongo/bson/bsontypes.h | 2 | ||||
-rw-r--r-- | src/mongo/bson/mutable/mutable_bson_test.cpp | 204 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_algo_test.cpp | 26 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_parser_leaf_test.cpp | 36 | ||||
-rw-r--r-- | src/mongo/db/ops/modifier_bit_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/ops/modifier_inc_test.cpp | 192 | ||||
-rw-r--r-- | src/mongo/dbtests/index_access_method_test.cpp | 18 | ||||
-rw-r--r-- | src/mongo/dbtests/jsobjtests.cpp | 15 | ||||
-rw-r--r-- | src/mongo/dbtests/jsontests.cpp | 8 | ||||
-rw-r--r-- | src/mongo/dbtests/jstests.cpp | 32 | ||||
-rw-r--r-- | src/mongo/platform/decimal128.h | 10 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/implscope.cpp | 4 | ||||
-rw-r--r-- | src/mongo/util/safe_num_test.cpp | 122 |
15 files changed, 422 insertions, 548 deletions
diff --git a/src/mongo/bson/bson_obj_test.cpp b/src/mongo/bson/bson_obj_test.cpp index 7e2288cce4f..6cf98fd998b 100644 --- a/src/mongo/bson/bson_obj_test.cpp +++ b/src/mongo/bson/bson_obj_test.cpp @@ -191,203 +191,170 @@ TEST(BSONObjCompare, NumberLong_Double) { } TEST(BSONObjCompare, NumberDecimalScaleAndZero) { - if (Decimal128::enabled) { - ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(1.0))); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(0.0))); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(1.0))); - - ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(0.1))); - ASSERT_LT(BSON("" << Decimal128(0.1)), BSON("" << Decimal128(1.0))); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(-0.1))); - ASSERT_LT(BSON("" << Decimal128(-0.1)), BSON("" << Decimal128(-0.0))); - ASSERT_LT(BSON("" << Decimal128(-0.1)), BSON("" << Decimal128(0.1))); - } + ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(1.0))); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(0.0))); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(1.0))); + + ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(0.1))); + ASSERT_LT(BSON("" << Decimal128(0.1)), BSON("" << Decimal128(1.0))); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << Decimal128(-0.1))); + ASSERT_LT(BSON("" << Decimal128(-0.1)), BSON("" << Decimal128(-0.0))); + ASSERT_LT(BSON("" << Decimal128(-0.1)), BSON("" << Decimal128(0.1))); } TEST(BSONObjCompare, NumberDecimalMaxAndMins) { - if (Decimal128::enabled) { - ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128::kSmallestPositive)); - ASSERT_GT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128::kLargestNegative)); - - // over 34 digits of precision so it should be equal - ASSERT_EQ(BSON("" << Decimal128(1.0)), - BSON("" << Decimal128(1.0).add(Decimal128::kSmallestPositive))); - ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(-0.0))); - - ASSERT_EQ(BSON("" << Decimal128(0)), BSON("" << Decimal128(0))); - ASSERT_EQ(BSON("" << Decimal128::kSmallestPositive), - BSON("" << Decimal128::kSmallestPositive)); - ASSERT_EQ(BSON("" << Decimal128::kLargestNegative), - BSON("" << Decimal128::kLargestNegative)); - } + ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128::kSmallestPositive)); + ASSERT_GT(BSON("" << Decimal128(0.0)), BSON("" << Decimal128::kLargestNegative)); + + // over 34 digits of precision so it should be equal + ASSERT_EQ(BSON("" << Decimal128(1.0)), + BSON("" << Decimal128(1.0).add(Decimal128::kSmallestPositive))); + ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << Decimal128(-0.0))); + + ASSERT_EQ(BSON("" << Decimal128(0)), BSON("" << Decimal128(0))); + ASSERT_EQ(BSON("" << Decimal128::kSmallestPositive), BSON("" << Decimal128::kSmallestPositive)); + ASSERT_EQ(BSON("" << Decimal128::kLargestNegative), BSON("" << Decimal128::kLargestNegative)); } TEST(BSONObjCompare, NumberDecimalInfinity) { - if (Decimal128::enabled) { - ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), BSON("" << Decimal128(0.0))); - ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << Decimal128::kLargestPositive)); - ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << Decimal128::kNegativeInfinity)); - - ASSERT_EQ(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << Decimal128::kPositiveInfinity)); - ASSERT_EQ(BSON("" << Decimal128::kNegativeInfinity), - BSON("" << Decimal128::kNegativeInfinity)); - - ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), BSON("" << Decimal128(0.0))); - ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), - BSON("" << Decimal128::kSmallestNegative)); - } + ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), BSON("" << Decimal128(0.0))); + ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), BSON("" << Decimal128::kLargestPositive)); + ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), BSON("" << Decimal128::kNegativeInfinity)); + + ASSERT_EQ(BSON("" << Decimal128::kPositiveInfinity), BSON("" << Decimal128::kPositiveInfinity)); + ASSERT_EQ(BSON("" << Decimal128::kNegativeInfinity), BSON("" << Decimal128::kNegativeInfinity)); + + ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), BSON("" << Decimal128(0.0))); + ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), BSON("" << Decimal128::kSmallestNegative)); } TEST(BSONObjCompare, NumberDecimalPosNaN) { - if (Decimal128::enabled) { - // +/-NaN is well ordered and compares smallest, so +NaN and -NaN should behave the same - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << 0.0)); - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kSmallestNegative)); - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kPositiveInfinity)); - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kNegativeInfinity)); - - ASSERT_EQ(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kNegativeNaN)); - } + // +/-NaN is well ordered and compares smallest, so +NaN and -NaN should behave the same + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << 0.0)); + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kSmallestNegative)); + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kPositiveInfinity)); + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kNegativeInfinity)); + + ASSERT_EQ(BSON("" << Decimal128::kPositiveNaN), BSON("" << Decimal128::kNegativeNaN)); } TEST(BSONObjCompare, NumberDecimalNegNan) { - if (Decimal128::enabled) { - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << 0.0)); - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kSmallestNegative)); - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kPositiveInfinity)); - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kNegativeInfinity)); + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << 0.0)); + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kSmallestNegative)); + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kPositiveInfinity)); + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kNegativeInfinity)); - ASSERT_EQ(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kPositiveNaN)); - } + ASSERT_EQ(BSON("" << Decimal128::kNegativeNaN), BSON("" << Decimal128::kPositiveNaN)); } TEST(BSONObjCompare, NumberDecimalCompareInt) { - if (Decimal128::enabled) { - ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0)); - ASSERT_EQ(BSON("" << Decimal128(502.0)), BSON("" << 502)); - ASSERT_EQ(BSON("" << Decimal128(std::numeric_limits<int>::max())), - BSON("" << std::numeric_limits<int>::max())); - ASSERT_EQ(BSON("" << Decimal128(-std::numeric_limits<int>::max())), - BSON("" << -std::numeric_limits<int>::max())); - - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), - BSON("" << -std::numeric_limits<int>::max())); - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), - BSON("" << -std::numeric_limits<int>::max())); - ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), - BSON("" << -std::numeric_limits<int>::max())); - ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << std::numeric_limits<int>::max())); - - ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0)); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << 0)); - } + ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0)); + ASSERT_EQ(BSON("" << Decimal128(502.0)), BSON("" << 502)); + ASSERT_EQ(BSON("" << Decimal128(std::numeric_limits<int>::max())), + BSON("" << std::numeric_limits<int>::max())); + ASSERT_EQ(BSON("" << Decimal128(-std::numeric_limits<int>::max())), + BSON("" << -std::numeric_limits<int>::max())); + + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), BSON("" << -std::numeric_limits<int>::max())); + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), BSON("" << -std::numeric_limits<int>::max())); + ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), + BSON("" << -std::numeric_limits<int>::max())); + ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), + BSON("" << std::numeric_limits<int>::max())); + + ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0)); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << 0)); } TEST(BSONObjCompare, NumberDecimalCompareLong) { - if (Decimal128::enabled) { - ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0ll)); - ASSERT_EQ(BSON("" << Decimal128(502.0)), BSON("" << 502ll)); - ASSERT_EQ(BSON("" << Decimal128(std::numeric_limits<int64_t>::max())), - BSON("" << std::numeric_limits<long long>::max())); - ASSERT_EQ(BSON("" << Decimal128(-std::numeric_limits<int64_t>::max())), - BSON("" << -std::numeric_limits<long long>::max())); - - ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), - BSON("" << -std::numeric_limits<long long>::max())); - ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), - BSON("" << -std::numeric_limits<long long>::max())); - ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), - BSON("" << -std::numeric_limits<long long>::max())); - ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << std::numeric_limits<long long>::max())); - - ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0ll)); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << 0ll)); - } + ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0ll)); + ASSERT_EQ(BSON("" << Decimal128(502.0)), BSON("" << 502ll)); + ASSERT_EQ(BSON("" << Decimal128(std::numeric_limits<int64_t>::max())), + BSON("" << std::numeric_limits<long long>::max())); + ASSERT_EQ(BSON("" << Decimal128(-std::numeric_limits<int64_t>::max())), + BSON("" << -std::numeric_limits<long long>::max())); + + ASSERT_LT(BSON("" << Decimal128::kNegativeNaN), + BSON("" << -std::numeric_limits<long long>::max())); + ASSERT_LT(BSON("" << Decimal128::kPositiveNaN), + BSON("" << -std::numeric_limits<long long>::max())); + ASSERT_LT(BSON("" << Decimal128::kNegativeInfinity), + BSON("" << -std::numeric_limits<long long>::max())); + ASSERT_GT(BSON("" << Decimal128::kPositiveInfinity), + BSON("" << std::numeric_limits<long long>::max())); + + ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0ll)); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << 0ll)); } TEST(BSONObjCompare, NumberDecimalCompareDoubleExactRepresentations) { - if (Decimal128::enabled) { - ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0.0)); - ASSERT_EQ(BSON("" << Decimal128(1.0)), BSON("" << 1.0)); - ASSERT_EQ(BSON("" << Decimal128(-1.0)), BSON("" << -1.0)); - ASSERT_EQ(BSON("" << Decimal128(0.125)), BSON("" << 0.125)); + ASSERT_EQ(BSON("" << Decimal128(0.0)), BSON("" << 0.0)); + ASSERT_EQ(BSON("" << Decimal128(1.0)), BSON("" << 1.0)); + ASSERT_EQ(BSON("" << Decimal128(-1.0)), BSON("" << -1.0)); + ASSERT_EQ(BSON("" << Decimal128(0.125)), BSON("" << 0.125)); - ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << 0.125)); - ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << -0.125)); + ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << 0.125)); + ASSERT_LT(BSON("" << Decimal128(-1.0)), BSON("" << -0.125)); - ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0.125)); - ASSERT_GT(BSON("" << Decimal128(0.0)), BSON("" << -0.125)); - } + ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0.125)); + ASSERT_GT(BSON("" << Decimal128(0.0)), BSON("" << -0.125)); } TEST(BSONObjCompare, NumberDecimalCompareDoubleNoDoubleRepresentation) { - if (Decimal128::enabled) { - // Double 0.1 should not compare the same as decimal 0.1. The standard - // double constructor for decimal types quantizes at 15 places, but this - // is not safe for a well ordered comparison because decimal(0.1) would - // then compare equal to both double(0.10000000000000000555) and - // double(0.999999999999999876). The following test cases check that - // proper well ordering is applied to double and decimal comparisons. - ASSERT_GT(BSON("" << Decimal128("0.3")), BSON("" << 0.1)); - ASSERT_LT(BSON("" << Decimal128("0.1")), BSON("" << 0.3)); - ASSERT_LT(BSON("" << Decimal128("-0.3")), BSON("" << -0.1)); - ASSERT_GT(BSON("" << Decimal128("-0.1")), BSON("" << -0.3)); - ASSERT_LT(BSON("" << Decimal128("0.1")), BSON("" << 0.1)); - ASSERT_GT(BSON("" << Decimal128("0.3")), BSON("" << 0.3)); - ASSERT_GT(BSON("" << Decimal128("-0.1")), BSON("" << -0.1)); - ASSERT_LT(BSON("" << Decimal128("-0.3")), BSON("" << -0.3)); - ASSERT_EQ(BSON("" << Decimal128("0.5")), BSON("" << 0.5)); - ASSERT_GT(BSON("" << Decimal128("0.5000000000000000000000000000000001")), BSON("" << 0.5)); - - // Double 0.1 should compare well against significantly different decimals - ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << 0.1)); - ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0.1)); - } + // Double 0.1 should not compare the same as decimal 0.1. The standard + // double constructor for decimal types quantizes at 15 places, but this + // is not safe for a well ordered comparison because decimal(0.1) would + // then compare equal to both double(0.10000000000000000555) and + // double(0.999999999999999876). The following test cases check that + // proper well ordering is applied to double and decimal comparisons. + ASSERT_GT(BSON("" << Decimal128("0.3")), BSON("" << 0.1)); + ASSERT_LT(BSON("" << Decimal128("0.1")), BSON("" << 0.3)); + ASSERT_LT(BSON("" << Decimal128("-0.3")), BSON("" << -0.1)); + ASSERT_GT(BSON("" << Decimal128("-0.1")), BSON("" << -0.3)); + ASSERT_LT(BSON("" << Decimal128("0.1")), BSON("" << 0.1)); + ASSERT_GT(BSON("" << Decimal128("0.3")), BSON("" << 0.3)); + ASSERT_GT(BSON("" << Decimal128("-0.1")), BSON("" << -0.1)); + ASSERT_LT(BSON("" << Decimal128("-0.3")), BSON("" << -0.3)); + ASSERT_EQ(BSON("" << Decimal128("0.5")), BSON("" << 0.5)); + ASSERT_GT(BSON("" << Decimal128("0.5000000000000000000000000000000001")), BSON("" << 0.5)); + + // Double 0.1 should compare well against significantly different decimals + ASSERT_LT(BSON("" << Decimal128(0.0)), BSON("" << 0.1)); + ASSERT_GT(BSON("" << Decimal128(1.0)), BSON("" << 0.1)); } TEST(BSONObjCompare, NumberDecimalCompareDoubleQuantize) { - if (Decimal128::enabled) { - // These tests deal with doubles that get adjusted when converted to decimal. - // The decimal type only will store a double's first 15 decimal digits of - // precision (the most it can accurately express). - Decimal128 roundedDoubleLargestPosValue("179769313486232E294"); - Decimal128 roundedDoubleOneAboveLargestPosValue("179769313486233E294"); - Decimal128 roundedDoubleLargestNegValue("-179769313486232E294"); - Decimal128 roundedDoubleOneAboveSmallestNegValue("-179769313486231E294"); - - ASSERT_EQ(BSON("" << roundedDoubleLargestPosValue), - BSON("" << Decimal128(std::numeric_limits<double>::max()))); - ASSERT_EQ(BSON("" << roundedDoubleLargestNegValue), - BSON("" << Decimal128(-std::numeric_limits<double>::max()))); - - ASSERT_GT(BSON("" << roundedDoubleOneAboveLargestPosValue), - BSON("" << Decimal128(std::numeric_limits<double>::max()))); - ASSERT_LT(BSON("" << roundedDoubleOneAboveSmallestNegValue), - BSON("" << Decimal128(-std::numeric_limits<double>::min()))); - } + // These tests deal with doubles that get adjusted when converted to decimal. + // The decimal type only will store a double's first 15 decimal digits of + // precision (the most it can accurately express). + Decimal128 roundedDoubleLargestPosValue("179769313486232E294"); + Decimal128 roundedDoubleOneAboveLargestPosValue("179769313486233E294"); + Decimal128 roundedDoubleLargestNegValue("-179769313486232E294"); + Decimal128 roundedDoubleOneAboveSmallestNegValue("-179769313486231E294"); + + ASSERT_EQ(BSON("" << roundedDoubleLargestPosValue), + BSON("" << Decimal128(std::numeric_limits<double>::max()))); + ASSERT_EQ(BSON("" << roundedDoubleLargestNegValue), + BSON("" << Decimal128(-std::numeric_limits<double>::max()))); + + ASSERT_GT(BSON("" << roundedDoubleOneAboveLargestPosValue), + BSON("" << Decimal128(std::numeric_limits<double>::max()))); + ASSERT_LT(BSON("" << roundedDoubleOneAboveSmallestNegValue), + BSON("" << Decimal128(-std::numeric_limits<double>::min()))); } TEST(BSONObjCompare, NumberDecimalCompareDoubleInfinity) { - if (Decimal128::enabled) { - ASSERT_EQ(BSON("" << Decimal128::kPositiveInfinity), - BSON("" << std::numeric_limits<double>::infinity())); - ASSERT_EQ(BSON("" << Decimal128::kNegativeInfinity), - BSON("" << -std::numeric_limits<double>::infinity())); - } + ASSERT_EQ(BSON("" << Decimal128::kPositiveInfinity), + BSON("" << std::numeric_limits<double>::infinity())); + ASSERT_EQ(BSON("" << Decimal128::kNegativeInfinity), + BSON("" << -std::numeric_limits<double>::infinity())); } TEST(BSONObjCompare, NumberDecimalCompareDoubleNaN) { - if (Decimal128::enabled) { - ASSERT_EQ(BSON("" << Decimal128::kPositiveNaN), - BSON("" << std::numeric_limits<double>::quiet_NaN())); - ASSERT_EQ(BSON("" << Decimal128::kNegativeNaN), - BSON("" << -std::numeric_limits<double>::quiet_NaN())); - } + ASSERT_EQ(BSON("" << Decimal128::kPositiveNaN), + BSON("" << std::numeric_limits<double>::quiet_NaN())); + ASSERT_EQ(BSON("" << Decimal128::kNegativeNaN), + BSON("" << -std::numeric_limits<double>::quiet_NaN())); } TEST(BSONObjCompare, StringSymbol) { diff --git a/src/mongo/bson/bson_validate.cpp b/src/mongo/bson/bson_validate.cpp index 9d9e489a964..0f5012d01f3 100644 --- a/src/mongo/bson/bson_validate.cpp +++ b/src/mongo/bson/bson_validate.cpp @@ -232,7 +232,7 @@ Status validateElementInfo(Buffer* buffer, return Status::OK(); case NumberDecimal: - if (Decimal128::enabled && buffer->version() != BSONVersion::kV1_0) { + if (buffer->version() != BSONVersion::kV1_0) { if (!buffer->skip(sizeof(Decimal128::Value))) return makeError("Invalid bson", idElem); return Status::OK(); diff --git a/src/mongo/bson/bsontypes.h b/src/mongo/bson/bsontypes.h index c33af5fc7c2..fa21b9e5020 100644 --- a/src/mongo/bson/bsontypes.h +++ b/src/mongo/bson/bsontypes.h @@ -112,7 +112,7 @@ enum BSONType { /** 128 bit decimal */ NumberDecimal = 19, /** max type that is not MaxKey */ - JSTypeMax = Decimal128::enabled ? 19 : 18, + JSTypeMax = 19, /** larger than all other types */ MaxKey = 127 }; diff --git a/src/mongo/bson/mutable/mutable_bson_test.cpp b/src/mongo/bson/mutable/mutable_bson_test.cpp index 0ec8dfdbcd6..3c865cea71a 100644 --- a/src/mongo/bson/mutable/mutable_bson_test.cpp +++ b/src/mongo/bson/mutable/mutable_bson_test.cpp @@ -564,10 +564,8 @@ TEST(Element, setters) { t0.setValueDouble(123.45); ASSERT_EQUALS(mongo::NumberDouble, t0.getType()); - if (mongo::Decimal128::enabled) { - t0.setValueDecimal(mongo::Decimal128("123.45E1234")); - ASSERT_EQUALS(mongo::NumberDecimal, t0.getType()); - } + t0.setValueDecimal(mongo::Decimal128("123.45E1234")); + ASSERT_EQUALS(mongo::NumberDecimal, t0.getType()); t0.setValueOID(mongo::OID("47cc67093475061e3d95369d")); ASSERT_EQUALS(mongo::jstOID, t0.getType()); @@ -614,40 +612,34 @@ TEST(Element, toString) { } TEST(DecimalType, createElement) { - if (mongo::Decimal128::enabled) { - mmb::Document doc; + mmb::Document doc; - mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("12345")); - ASSERT_TRUE(mongo::Decimal128("12345").isEqual(d0.getValueDecimal())); - } + mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("12345")); + ASSERT_TRUE(mongo::Decimal128("12345").isEqual(d0.getValueDecimal())); } TEST(DecimalType, setElement) { - if (mongo::Decimal128::enabled) { - mmb::Document doc; + mmb::Document doc; - mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("128")); - d0.setValueDecimal(mongo::Decimal128("123456")); - ASSERT_TRUE(mongo::Decimal128("123456").isEqual(d0.getValueDecimal())); + mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("128")); + d0.setValueDecimal(mongo::Decimal128("123456")); + ASSERT_TRUE(mongo::Decimal128("123456").isEqual(d0.getValueDecimal())); - d0.setValueDouble(0.1); - ASSERT_EQUALS(0.1, d0.getValueDouble()); - d0.setValueDecimal(mongo::Decimal128("23")); - ASSERT_TRUE(mongo::Decimal128("23").isEqual(d0.getValueDecimal())); - } + d0.setValueDouble(0.1); + ASSERT_EQUALS(0.1, d0.getValueDouble()); + d0.setValueDecimal(mongo::Decimal128("23")); + ASSERT_TRUE(mongo::Decimal128("23").isEqual(d0.getValueDecimal())); } TEST(DecimalType, appendElement) { - if (mongo::Decimal128::enabled) { - mmb::Document doc; + mmb::Document doc; - mmb::Element d0 = doc.makeElementObject("e0"); - d0.appendDecimal("precision", mongo::Decimal128(34)); + mmb::Element d0 = doc.makeElementObject("e0"); + d0.appendDecimal("precision", mongo::Decimal128(34)); - mmb::Element it = mmb::findFirstChildNamed(d0, "precision"); - ASSERT_TRUE(it.ok()); - ASSERT_TRUE(mongo::Decimal128(34).isEqual(it.getValueDecimal())); - } + mmb::Element it = mmb::findFirstChildNamed(d0, "precision"); + ASSERT_TRUE(it.ok()); + ASSERT_TRUE(mongo::Decimal128(34).isEqual(it.getValueDecimal())); } TEST(TimestampType, createElement) { @@ -716,12 +708,10 @@ TEST(SafeNumType, getSafeNum) { num = t0.getValueSafeNum(); ASSERT_EQUALS(num, 123.456789); - if (mongo::Decimal128::enabled) { - t0.setValueDecimal(mongo::Decimal128("12345678.1234")); - ASSERT_TRUE(mongo::Decimal128("12345678.1234").isEqual(t0.getValueDecimal())); - num = t0.getValueSafeNum(); - ASSERT_EQUALS(num, mongo::Decimal128("12345678.1234")); - } + t0.setValueDecimal(mongo::Decimal128("12345678.1234")); + ASSERT_TRUE(mongo::Decimal128("12345678.1234").isEqual(t0.getValueDecimal())); + num = t0.getValueSafeNum(); + ASSERT_EQUALS(num, mongo::Decimal128("12345678.1234")); } TEST(SafeNumType, setSafeNum) { @@ -814,11 +804,7 @@ static const char jsonSampleWithDecimal[] = TEST(Serialization, RoundTrip) { mongo::BSONObj obj; - if (mongo::Decimal128::enabled) { - obj = mongo::fromjson(jsonSampleWithDecimal); - } else { - obj = mongo::fromjson(jsonSample); - } + obj = mongo::fromjson(jsonSampleWithDecimal); mmb::Document doc(obj.copy()); mongo::BSONObj built = doc.getObject(); ASSERT_EQUALS(obj, built); @@ -1387,10 +1373,8 @@ TEST(Element, IsNumeric) { elt = doc.makeElementDouble("dummy", 42.0); ASSERT_TRUE(elt.isNumeric()); - if (mongo::Decimal128::enabled) { - elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20)); - ASSERT_TRUE(elt.isNumeric()); - } + elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20)); + ASSERT_TRUE(elt.isNumeric()); } TEST(Element, IsIntegral) { @@ -1411,10 +1395,8 @@ TEST(Element, IsIntegral) { elt = doc.makeElementDouble("dummy", 42.0); ASSERT_FALSE(elt.isIntegral()); - if (mongo::Decimal128::enabled) { - elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20)); - ASSERT_FALSE(elt.isIntegral()); - } + elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20)); + ASSERT_FALSE(elt.isIntegral()); } TEST(Document, ArraySerialization) { @@ -2576,45 +2558,43 @@ TEST(TypeSupport, EncodingEquivalenceLong) { } TEST(TypeSupport, EncodingEquivalenceDecimal) { - if (mongo::Decimal128::enabled) { - mongo::BSONObjBuilder builder; - const char name[] = "thing"; - const mongo::Decimal128 value1 = mongo::Decimal128(2); - builder.append(name, value1); - mongo::BSONObj source = builder.done(); - const mongo::BSONElement thing = source.firstElement(); - ASSERT_TRUE(thing.type() == mongo::NumberDecimal); - - mmb::Document doc; - - // Construct via direct call to append/make - ASSERT_OK(doc.root().appendDecimal(name, value1)); - mmb::Element a = doc.root().rightChild(); - ASSERT_TRUE(a.ok()); - ASSERT_EQUALS(a.getType(), mongo::NumberDecimal); - ASSERT_TRUE(a.hasValue()); - ASSERT_TRUE(value1.isEqual(mmb::ConstElement(a).getValueDecimal())); - - // Construct via call passong BSON element - ASSERT_OK(doc.root().appendElement(thing)); - mmb::Element b = doc.root().rightChild(); - ASSERT_TRUE(b.ok()); - ASSERT_EQUALS(b.getType(), mongo::NumberDecimal); - ASSERT_TRUE(b.hasValue()); - - // Construct via setValue call - ASSERT_OK(doc.root().appendNull(name)); - mmb::Element c = doc.root().rightChild(); - ASSERT_TRUE(c.ok()); - c.setValueDecimal(value1); - ASSERT_EQUALS(c.getType(), mongo::NumberDecimal); - ASSERT_TRUE(c.hasValue()); - - // Ensure identity: - ASSERT_TRUE(identical(thing, mmb::ConstElement(a).getValue())); - ASSERT_TRUE(identical(a.getValue(), b.getValue())); - ASSERT_TRUE(identical(b.getValue(), c.getValue())); - } + mongo::BSONObjBuilder builder; + const char name[] = "thing"; + const mongo::Decimal128 value1 = mongo::Decimal128(2); + builder.append(name, value1); + mongo::BSONObj source = builder.done(); + const mongo::BSONElement thing = source.firstElement(); + ASSERT_TRUE(thing.type() == mongo::NumberDecimal); + + mmb::Document doc; + + // Construct via direct call to append/make + ASSERT_OK(doc.root().appendDecimal(name, value1)); + mmb::Element a = doc.root().rightChild(); + ASSERT_TRUE(a.ok()); + ASSERT_EQUALS(a.getType(), mongo::NumberDecimal); + ASSERT_TRUE(a.hasValue()); + ASSERT_TRUE(value1.isEqual(mmb::ConstElement(a).getValueDecimal())); + + // Construct via call passong BSON element + ASSERT_OK(doc.root().appendElement(thing)); + mmb::Element b = doc.root().rightChild(); + ASSERT_TRUE(b.ok()); + ASSERT_EQUALS(b.getType(), mongo::NumberDecimal); + ASSERT_TRUE(b.hasValue()); + + // Construct via setValue call + ASSERT_OK(doc.root().appendNull(name)); + mmb::Element c = doc.root().rightChild(); + ASSERT_TRUE(c.ok()); + c.setValueDecimal(value1); + ASSERT_EQUALS(c.getType(), mongo::NumberDecimal); + ASSERT_TRUE(c.hasValue()); + + // Ensure identity: + ASSERT_TRUE(identical(thing, mmb::ConstElement(a).getValue())); + ASSERT_TRUE(identical(a.getValue(), b.getValue())); + ASSERT_TRUE(identical(b.getValue(), c.getValue())); } TEST(TypeSupport, EncodingEquivalenceMinKey) { @@ -3141,34 +3121,32 @@ TEST(DocumentInPlace, NumberDoubleLifecycle) { } TEST(DocumentInPlace, NumberDecimalLifecycle) { - if (mongo::Decimal128::enabled) { - const mongo::Decimal128 value1 = mongo::Decimal128(32); - const mongo::Decimal128 value2 = mongo::Decimal128(2); - - mongo::BSONObj obj(BSON("x" << value1)); - mmb::Document doc(obj, mmb::Document::kInPlaceEnabled); - - mmb::Element x = doc.root().leftChild(); - - mmb::DamageVector damages; - const char* source = NULL; - - x.setValueDecimal(value2); - ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source)); - ASSERT_EQUALS(1U, damages.size()); - apply(&obj, damages, source); - ASSERT_TRUE(x.hasValue()); - ASSERT_TRUE(x.isType(mongo::NumberDecimal)); - ASSERT_TRUE(value2.isEqual(x.getValueDecimal())); - - // TODO: Re-enable when in-place updates to leaf elements is supported - // x.setValueDecimal(value1); - // ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source)); - // apply(&obj, damages, source); - // ASSERT_TRUE(x.hasValue()); - // ASSERT_TRUE(x.isType(mongo::NumberDecimal)); - // ASSERT_TRUE(value1.isEqual(x.getValueDecimal())); - } + const mongo::Decimal128 value1 = mongo::Decimal128(32); + const mongo::Decimal128 value2 = mongo::Decimal128(2); + + mongo::BSONObj obj(BSON("x" << value1)); + mmb::Document doc(obj, mmb::Document::kInPlaceEnabled); + + mmb::Element x = doc.root().leftChild(); + + mmb::DamageVector damages; + const char* source = NULL; + + x.setValueDecimal(value2); + ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source)); + ASSERT_EQUALS(1U, damages.size()); + apply(&obj, damages, source); + ASSERT_TRUE(x.hasValue()); + ASSERT_TRUE(x.isType(mongo::NumberDecimal)); + ASSERT_TRUE(value2.isEqual(x.getValueDecimal())); + + // TODO: Re-enable when in-place updates to leaf elements is supported + // x.setValueDecimal(value1); + // ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source)); + // apply(&obj, damages, source); + // ASSERT_TRUE(x.hasValue()); + // ASSERT_TRUE(x.isType(mongo::NumberDecimal)); + // ASSERT_TRUE(value1.isEqual(x.getValueDecimal())); } // Doubles and longs are the same size, 8 bytes, so we should be able to do in-place diff --git a/src/mongo/db/matcher/expression_algo_test.cpp b/src/mongo/db/matcher/expression_algo_test.cpp index 946120d353d..73d3a5b8b88 100644 --- a/src/mongo/db/matcher/expression_algo_test.cpp +++ b/src/mongo/db/matcher/expression_algo_test.cpp @@ -132,20 +132,18 @@ TEST(ExpressionAlgoIsSubsetOf, Compare_NaN) { ASSERT_FALSE(expression::isSubsetOf(nan.get(), in.get())); ASSERT_FALSE(expression::isSubsetOf(in.get(), nan.get())); - if (Decimal128::enabled) { - ParsedMatchExpression decNan("{x : NumberDecimal(\"NaN\") }"); - ASSERT_TRUE(expression::isSubsetOf(decNan.get(), decNan.get())); - ASSERT_TRUE(expression::isSubsetOf(nan.get(), decNan.get())); - ASSERT_TRUE(expression::isSubsetOf(decNan.get(), nan.get())); - ASSERT_FALSE(expression::isSubsetOf(decNan.get(), lt.get())); - ASSERT_FALSE(expression::isSubsetOf(lt.get(), decNan.get())); - ASSERT_FALSE(expression::isSubsetOf(decNan.get(), lte.get())); - ASSERT_FALSE(expression::isSubsetOf(lte.get(), decNan.get())); - ASSERT_FALSE(expression::isSubsetOf(decNan.get(), gte.get())); - ASSERT_FALSE(expression::isSubsetOf(gte.get(), decNan.get())); - ASSERT_FALSE(expression::isSubsetOf(decNan.get(), gt.get())); - ASSERT_FALSE(expression::isSubsetOf(gt.get(), decNan.get())); - } + ParsedMatchExpression decNan("{x : NumberDecimal(\"NaN\") }"); + ASSERT_TRUE(expression::isSubsetOf(decNan.get(), decNan.get())); + ASSERT_TRUE(expression::isSubsetOf(nan.get(), decNan.get())); + ASSERT_TRUE(expression::isSubsetOf(decNan.get(), nan.get())); + ASSERT_FALSE(expression::isSubsetOf(decNan.get(), lt.get())); + ASSERT_FALSE(expression::isSubsetOf(lt.get(), decNan.get())); + ASSERT_FALSE(expression::isSubsetOf(decNan.get(), lte.get())); + ASSERT_FALSE(expression::isSubsetOf(lte.get(), decNan.get())); + ASSERT_FALSE(expression::isSubsetOf(decNan.get(), gte.get())); + ASSERT_FALSE(expression::isSubsetOf(gte.get(), decNan.get())); + ASSERT_FALSE(expression::isSubsetOf(decNan.get(), gt.get())); + ASSERT_FALSE(expression::isSubsetOf(gt.get(), decNan.get())); } TEST(ExpressionAlgoIsSubsetOf, Compare_EQ) { diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index a6836126ef4..b0897f8468e 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -965,16 +965,14 @@ TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) { } TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) { - if (Decimal128::enabled) { - BSONObj query = BSON("x" << BSON("$type" << mongo::NumberDecimal)); - const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); - ASSERT_TRUE(result.isOK()); + BSONObj query = BSON("x" << BSON("$type" << mongo::NumberDecimal)); + const CollatorInterface* collator = nullptr; + StatusWithMatchExpression result = + MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + ASSERT_TRUE(result.isOK()); - ASSERT_FALSE(result.getValue()->matchesBSON(BSON("x" << 5.3))); - ASSERT_TRUE(result.getValue()->matchesBSON(BSON("x" << mongo::Decimal128("1")))); - } + ASSERT_FALSE(result.getValue()->matchesBSON(BSON("x" << 5.3))); + ASSERT_TRUE(result.getValue()->matchesBSON(BSON("x" << mongo::Decimal128("1")))); } TEST(MatchExpressionParserLeafTest, TypeNull) { @@ -1042,17 +1040,15 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { } TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) { - if (Decimal128::enabled) { - const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumberDecimal = MatchExpressionParser::parse( - fromjson("{a: {$type: 'decimal'}}"), ExtensionsCallbackDisallowExtensions(), collator); - ASSERT_OK(typeNumberDecimal.getStatus()); - TypeMatchExpression* tmeNumberDecimal = - static_cast<TypeMatchExpression*>(typeNumberDecimal.getValue().get()); - ASSERT(tmeNumberDecimal->getType() == NumberDecimal); - ASSERT_TRUE(tmeNumberDecimal->matchesBSON(BSON("a" << mongo::Decimal128("1")))); - ASSERT_FALSE(tmeNumberDecimal->matchesBSON(fromjson("{a: true}"))); - } + const CollatorInterface* collator = nullptr; + StatusWithMatchExpression typeNumberDecimal = MatchExpressionParser::parse( + fromjson("{a: {$type: 'decimal'}}"), ExtensionsCallbackDisallowExtensions(), collator); + ASSERT_OK(typeNumberDecimal.getStatus()); + TypeMatchExpression* tmeNumberDecimal = + static_cast<TypeMatchExpression*>(typeNumberDecimal.getValue().get()); + ASSERT(tmeNumberDecimal->getType() == NumberDecimal); + ASSERT_TRUE(tmeNumberDecimal->matchesBSON(BSON("a" << mongo::Decimal128("1")))); + ASSERT_FALSE(tmeNumberDecimal->matchesBSON(fromjson("{a: true}"))); } TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) { diff --git a/src/mongo/db/ops/modifier_bit_test.cpp b/src/mongo/db/ops/modifier_bit_test.cpp index 34efbb0a7a7..dbc4d7ba0b2 100644 --- a/src/mongo/db/ops/modifier_bit_test.cpp +++ b/src/mongo/db/ops/modifier_bit_test.cpp @@ -129,12 +129,10 @@ TEST(Init, FailToInitWithInvalidValue) { ASSERT_NOT_OK(mod.init(modObj["$bit"].embeddedObject().firstElement(), ModifierInterface::Options::normal())); - if (mongo::Decimal128::enabled) { - // The argument to the sub-operator must be integral - modObj = fromjson("{ $bit : { a : { or : NumberDecimal(\"1.0\") } } }"); - ASSERT_NOT_OK(mod.init(modObj["$bit"].embeddedObject().firstElement(), - ModifierInterface::Options::normal())); - } + // The argument to the sub-operator must be integral + modObj = fromjson("{ $bit : { a : { or : NumberDecimal(\"1.0\") } } }"); + ASSERT_NOT_OK(mod.init(modObj["$bit"].embeddedObject().firstElement(), + ModifierInterface::Options::normal())); } TEST(Init, ParsesAndInt) { diff --git a/src/mongo/db/ops/modifier_inc_test.cpp b/src/mongo/db/ops/modifier_inc_test.cpp index 904802a7ad9..02fbbd4474a 100644 --- a/src/mongo/db/ops/modifier_inc_test.cpp +++ b/src/mongo/db/ops/modifier_inc_test.cpp @@ -125,9 +125,7 @@ TEST(Init, InitParsesNumberDouble) { } TEST(Init, InitParsesNumberDecimal) { - if (mongo::Decimal128::enabled) { - Mod incMod(BSON("$inc" << BSON("a" << Decimal128(1.0)))); - } + Mod incMod(BSON("$inc" << BSON("a" << Decimal128(1.0)))); } TEST(SimpleMod, PrepareSimpleOK) { @@ -284,13 +282,11 @@ TEST(NoOp, Double) { } TEST(NoOp, Decimal) { - if (mongo::Decimal128::enabled) { - Document doc(BSON("a" << Decimal128("1.0"))); - Mod incMod(BSON("$inc" << BSON("a" << Decimal128("0.0")))); - ModifierInterface::ExecInfo execInfo; - ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); - ASSERT_TRUE(execInfo.noOp); - } + Document doc(BSON("a" << Decimal128("1.0"))); + Mod incMod(BSON("$inc" << BSON("a" << Decimal128("0.0")))); + ModifierInterface::ExecInfo execInfo; + ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); + ASSERT_TRUE(execInfo.noOp); } TEST(Upcasting, UpcastIntToLong) { @@ -389,107 +385,99 @@ TEST(Upcasting, DoublesStayDoubles) { } TEST(Upcasting, UpcastIntToDecimal) { - if (mongo::Decimal128::enabled) { - // Checks that $inc : NumberDecimal(0) turns a NumberInt into a NumberDecimal and logs it - // correctly. - Document doc(BSON("a" << static_cast<int>(1))); - ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType()); - - Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); - - ModifierInterface::ExecInfo execInfo; - ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); - ASSERT_FALSE(execInfo.noOp); - - ASSERT_OK(incMod.apply()); - ASSERT_FALSE(doc.isInPlaceModeEnabled()); - ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); - ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); - - Document logDoc; - LogBuilder logBuilder(logDoc.root()); - ASSERT_OK(incMod.log(&logBuilder)); - ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); - ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); - } + // Checks that $inc : NumberDecimal(0) turns a NumberInt into a NumberDecimal and logs it + // correctly. + Document doc(BSON("a" << static_cast<int>(1))); + ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType()); + + Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); + + ModifierInterface::ExecInfo execInfo; + ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); + ASSERT_FALSE(execInfo.noOp); + + ASSERT_OK(incMod.apply()); + ASSERT_FALSE(doc.isInPlaceModeEnabled()); + ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); + ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); + + Document logDoc; + LogBuilder logBuilder(logDoc.root()); + ASSERT_OK(incMod.log(&logBuilder)); + ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); + ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); } TEST(Upcasting, UpcastLongToDecimal) { - if (mongo::Decimal128::enabled) { - // Checks that $inc : NumberDecimal(0) turns a NumberLong into a NumberDecimal and logs it - // correctly. - Document doc(BSON("a" << static_cast<long long>(1))); - ASSERT_EQUALS(mongo::NumberLong, doc.root()["a"].getType()); - - Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); - - ModifierInterface::ExecInfo execInfo; - ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); - ASSERT_FALSE(execInfo.noOp); - - ASSERT_OK(incMod.apply()); - ASSERT_FALSE(doc.isInPlaceModeEnabled()); - ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); - ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); - - Document logDoc; - LogBuilder logBuilder(logDoc.root()); - ASSERT_OK(incMod.log(&logBuilder)); - ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); - ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); - } + // Checks that $inc : NumberDecimal(0) turns a NumberLong into a NumberDecimal and logs it + // correctly. + Document doc(BSON("a" << static_cast<long long>(1))); + ASSERT_EQUALS(mongo::NumberLong, doc.root()["a"].getType()); + + Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); + + ModifierInterface::ExecInfo execInfo; + ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); + ASSERT_FALSE(execInfo.noOp); + + ASSERT_OK(incMod.apply()); + ASSERT_FALSE(doc.isInPlaceModeEnabled()); + ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); + ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); + + Document logDoc; + LogBuilder logBuilder(logDoc.root()); + ASSERT_OK(incMod.log(&logBuilder)); + ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); + ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); } TEST(Upcasting, UpcastDoubleToDecimal) { - if (mongo::Decimal128::enabled) { - // Checks that $inc : NumberDecimal(0) turns a double into a NumberDecimal and logs it - // correctly. - Document doc(BSON("a" << static_cast<double>(1.0))); - ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType()); - - Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); - - ModifierInterface::ExecInfo execInfo; - ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); - ASSERT_FALSE(execInfo.noOp); - - ASSERT_OK(incMod.apply()); - ASSERT_FALSE(doc.isInPlaceModeEnabled()); - ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); - ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); - - Document logDoc; - LogBuilder logBuilder(logDoc.root()); - ASSERT_OK(incMod.log(&logBuilder)); - ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); - ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); - } + // Checks that $inc : NumberDecimal(0) turns a double into a NumberDecimal and logs it + // correctly. + Document doc(BSON("a" << static_cast<double>(1.0))); + ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType()); + + Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"0\") }}")); + + ModifierInterface::ExecInfo execInfo; + ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); + ASSERT_FALSE(execInfo.noOp); + + ASSERT_OK(incMod.apply()); + ASSERT_FALSE(doc.isInPlaceModeEnabled()); + ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"1.0\") }"), doc); + ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); + + Document logDoc; + LogBuilder logBuilder(logDoc.root()); + ASSERT_OK(incMod.log(&logBuilder)); + ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"1.0\") }}"), logDoc); + ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); } TEST(Upcasting, DecimalsStayDecimals) { - if (mongo::Decimal128::enabled) { - // Checks that $inc : NumberDecimal(1) keeps a NumberDecimal as a NumberDecimal and logs it - // correctly. - Document doc(BSON("a" << mongo::Decimal128("1.0"))); - ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); - - Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"1\") }}")); - - ModifierInterface::ExecInfo execInfo; - ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); - ASSERT_FALSE(execInfo.noOp); - - ASSERT_OK(incMod.apply()); - ASSERT_TRUE(doc.isInPlaceModeEnabled()); - ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"2.0\") }"), doc); - ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); - - Document logDoc; - LogBuilder logBuilder(logDoc.root()); - ASSERT_OK(incMod.log(&logBuilder)); - ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"2.0\") }}"), logDoc); - ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); - } + // Checks that $inc : NumberDecimal(1) keeps a NumberDecimal as a NumberDecimal and logs it + // correctly. + Document doc(BSON("a" << mongo::Decimal128("1.0"))); + ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); + + Mod incMod(fromjson("{ $inc : { a : NumberDecimal(\"1\") }}")); + + ModifierInterface::ExecInfo execInfo; + ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo)); + ASSERT_FALSE(execInfo.noOp); + + ASSERT_OK(incMod.apply()); + ASSERT_TRUE(doc.isInPlaceModeEnabled()); + ASSERT_EQUALS(fromjson("{ a : NumberDecimal(\"2.0\") }"), doc); + ASSERT_EQUALS(mongo::NumberDecimal, doc.root()["a"].getType()); + + Document logDoc; + LogBuilder logBuilder(logDoc.root()); + ASSERT_OK(incMod.log(&logBuilder)); + ASSERT_EQUALS(fromjson("{ $set : { a : NumberDecimal(\"2.0\") }}"), logDoc); + ASSERT_EQUALS(mongo::NumberDecimal, logDoc.root()["$set"]["a"].getType()); } // The only interesting overflow cases are int->long via increment: we never overflow to diff --git a/src/mongo/dbtests/index_access_method_test.cpp b/src/mongo/dbtests/index_access_method_test.cpp index e9cbf32fac1..35e6cd020f9 100644 --- a/src/mongo/dbtests/index_access_method_test.cpp +++ b/src/mongo/dbtests/index_access_method_test.cpp @@ -106,19 +106,17 @@ TEST(IndexAccessMethodSetDifference, ZerosOfDifferentTypesAreNotEquivalent) { assertDistinct(doubleObj, intObj); assertDistinct(doubleObj, longObj); - if (mongo::Decimal128::enabled) { - const BSONObj decimalObj = fromjson("{'': NumberDecimal('0')}"); + const BSONObj decimalObj = fromjson("{'': NumberDecimal('0')}"); - ASSERT_EQ(0, doubleObj.woCompare(decimalObj)); + ASSERT_EQ(0, doubleObj.woCompare(decimalObj)); - assertDistinct(intObj, decimalObj); - assertDistinct(longObj, decimalObj); - assertDistinct(doubleObj, decimalObj); + assertDistinct(intObj, decimalObj); + assertDistinct(longObj, decimalObj); + assertDistinct(doubleObj, decimalObj); - assertDistinct(decimalObj, intObj); - assertDistinct(decimalObj, longObj); - assertDistinct(decimalObj, doubleObj); - } + assertDistinct(decimalObj, intObj); + assertDistinct(decimalObj, longObj); + assertDistinct(decimalObj, doubleObj); } TEST(IndexAccessMethodSetDifference, ShouldDetectOneDifferenceAmongManySimilarities) { diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp index a9a3638d462..13579765dfb 100644 --- a/src/mongo/dbtests/jsobjtests.cpp +++ b/src/mongo/dbtests/jsobjtests.cpp @@ -711,9 +711,7 @@ struct AppendNumber { b.appendNumber("c", (1024LL * 1024 * 1024) - 1); b.appendNumber("d", (1024LL * 1024 * 1024 * 1024) - 1); b.appendNumber("e", 1024LL * 1024 * 1024 * 1024 * 1024 * 1024); - if (Decimal128::enabled) { - b.appendNumber("f", mongo::Decimal128("1")); - } + b.appendNumber("f", mongo::Decimal128("1")); BSONObj o = b.obj(); keyTest(o); @@ -723,10 +721,7 @@ struct AppendNumber { ASSERT(o["c"].type() == NumberInt); ASSERT(o["d"].type() == NumberDouble); ASSERT(o["e"].type() == NumberLong); - - if (Decimal128::enabled) { - ASSERT(o["f"].type() == NumberDecimal); - } + ASSERT(o["f"].type() == NumberDecimal); } }; @@ -1627,10 +1622,8 @@ public: ASSERT_EQUALS(objTypeOf(1LL), NumberLong); ASSERT_EQUALS(arrTypeOf(1LL), NumberLong); - if (Decimal128::enabled) { - ASSERT_EQUALS(objTypeOf(mongo::Decimal128("1")), NumberDecimal); - ASSERT_EQUALS(arrTypeOf(mongo::Decimal128("1")), NumberDecimal); - } + ASSERT_EQUALS(objTypeOf(mongo::Decimal128("1")), NumberDecimal); + ASSERT_EQUALS(arrTypeOf(mongo::Decimal128("1")), NumberDecimal); ASSERT_EQUALS(objTypeOf(MAXKEY), MaxKey); ASSERT_EQUALS(arrTypeOf(MAXKEY), MaxKey); diff --git a/src/mongo/dbtests/jsontests.cpp b/src/mongo/dbtests/jsontests.cpp index b2a703fc78a..04a5b375a34 100644 --- a/src/mongo/dbtests/jsontests.cpp +++ b/src/mongo/dbtests/jsontests.cpp @@ -2717,12 +2717,8 @@ public: add<JsonStringTests::NumberLongStrict>(); add<JsonStringTests::NumberLongStrictLarge>(); add<JsonStringTests::NumberLongStrictNegative>(); - - if (Decimal128::enabled) { - add<JsonStringTests::NumberDecimal>(); - add<JsonStringTests::NumberDecimalStrict>(); - } - + add<JsonStringTests::NumberDecimal>(); + add<JsonStringTests::NumberDecimalStrict>(); add<JsonStringTests::NumberDoubleNaN>(); add<JsonStringTests::NumberDoubleInfinity>(); add<JsonStringTests::NumberDoubleNegativeInfinity>(); diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp index 798a6224919..35a23e99f6c 100644 --- a/src/mongo/dbtests/jstests.cpp +++ b/src/mongo/dbtests/jstests.cpp @@ -2398,11 +2398,9 @@ public: add<NumberLong>(); add<NumberLong2>(); - if (Decimal128::enabled) { - add<NumberDecimal>(); - add<NumberDecimalGetFromScope>(); - add<NumberDecimalBigObject>(); - } + add<NumberDecimal>(); + add<NumberDecimalGetFromScope>(); + add<NumberDecimalBigObject>(); add<MaxTimestamp>(); add<RenameTest>(); @@ -2476,19 +2474,17 @@ public: add<RoundTripTests::NumberInt>(); add<RoundTripTests::Number>(); - if (Decimal128::enabled) { - add<RoundTripTests::NumberDecimal>(); - add<RoundTripTests::NumberDecimalNegative>(); - add<RoundTripTests::NumberDecimalMax>(); - add<RoundTripTests::NumberDecimalMin>(); - add<RoundTripTests::NumberDecimalPositiveZero>(); - add<RoundTripTests::NumberDecimalNegativeZero>(); - add<RoundTripTests::NumberDecimalPositiveNaN>(); - add<RoundTripTests::NumberDecimalNegativeNaN>(); - add<RoundTripTests::NumberDecimalPositiveInfinity>(); - add<RoundTripTests::NumberDecimalNegativeInfinity>(); - add<RoundTripTests::NumberDecimalPrecision>(); - } + add<RoundTripTests::NumberDecimal>(); + add<RoundTripTests::NumberDecimalNegative>(); + add<RoundTripTests::NumberDecimalMax>(); + add<RoundTripTests::NumberDecimalMin>(); + add<RoundTripTests::NumberDecimalPositiveZero>(); + add<RoundTripTests::NumberDecimalNegativeZero>(); + add<RoundTripTests::NumberDecimalPositiveNaN>(); + add<RoundTripTests::NumberDecimalNegativeNaN>(); + add<RoundTripTests::NumberDecimalPositiveInfinity>(); + add<RoundTripTests::NumberDecimalNegativeInfinity>(); + add<RoundTripTests::NumberDecimalPrecision>(); add<RoundTripTests::UUID>(); add<RoundTripTests::HexData>(); diff --git a/src/mongo/platform/decimal128.h b/src/mongo/platform/decimal128.h index 9481a30ccd1..4ef6c8da60b 100644 --- a/src/mongo/platform/decimal128.h +++ b/src/mongo/platform/decimal128.h @@ -48,16 +48,6 @@ namespace mongo { */ class Decimal128 { public: -/** - * This boolean is used as a master switch to enable and disable decimal support. - * TODO(SERVER-23553): Remove once s390 decimal support is working - */ -#if defined(__s390x__) - static const bool enabled = false; -#else - static const bool enabled = true; -#endif - /** * Static constants to get Decimal128 representations of specific numbers * kLargestPositive -> 9999999999999999999999999999999999E6111 diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp index 3559e16a9b7..15affbd0b1e 100644 --- a/src/mongo/scripting/mozjs/implscope.cpp +++ b/src/mongo/scripting/mozjs/implscope.cpp @@ -772,9 +772,7 @@ void MozJSImplScope::installBSONTypes() { _nativeFunctionProto.install(_global); _numberIntProto.install(_global); _numberLongProto.install(_global); - if (Decimal128::enabled) { - _numberDecimalProto.install(_global); - } + _numberDecimalProto.install(_global); _objectProto.install(_global); _oidProto.install(_global); _regExpProto.install(_global); diff --git a/src/mongo/util/safe_num_test.cpp b/src/mongo/util/safe_num_test.cpp index cf70af01670..4086729e9c6 100644 --- a/src/mongo/util/safe_num_test.cpp +++ b/src/mongo/util/safe_num_test.cpp @@ -51,20 +51,14 @@ TEST(Basics, Initialization) { const SafeNum numDouble(0.0); ASSERT_EQUALS(numDouble.type(), mongo::NumberDouble); - if (mongo::Decimal128::enabled) { - const SafeNum numDecimal(Decimal128("1.0")); - ASSERT_EQUALS(numDecimal.type(), mongo::NumberDecimal); - } + const SafeNum numDecimal(Decimal128("1.0")); + ASSERT_EQUALS(numDecimal.type(), mongo::NumberDecimal); } TEST(Basics, BSONElementInitialization) { mongo::BSONObj o; - if (mongo::Decimal128::enabled) { - o = BSON("numberInt" << 1 << "numberLong" << 1LL << "numberDouble" << 0.1 << "NumberDecimal" - << Decimal128("1")); - } else { - o = BSON("numberInt" << 1 << "numberLong" << 1LL << "numberDouble" << 0.1); - } + o = BSON("numberInt" << 1 << "numberLong" << 1LL << "numberDouble" << 0.1 << "NumberDecimal" + << Decimal128("1")); const SafeNum numInt(o.getField("numberInt")); ASSERT_EQUALS(numInt.type(), mongo::NumberInt); @@ -75,10 +69,8 @@ TEST(Basics, BSONElementInitialization) { const SafeNum numDouble(o.getField("numberDouble")); ASSERT_EQUALS(numDouble.type(), mongo::NumberDouble); - if (mongo::Decimal128::enabled) { - const SafeNum numDecimal(o.getField("NumberDecimal")); - ASSERT_EQUALS(numDecimal.type(), mongo::NumberDecimal); - } + const SafeNum numDecimal(o.getField("NumberDecimal")); + ASSERT_EQUALS(numDecimal.type(), mongo::NumberDecimal); } TEST(Comparison, EOO) { @@ -104,11 +96,9 @@ TEST(Comparison, StrictTypeComparison) { ASSERT_FALSE(oneDouble.isIdentical(one)); ASSERT_TRUE(oneDouble.isIdentical(oneDouble)); - if (mongo::Decimal128::enabled) { - const SafeNum oneDecimal(Decimal128(1)); - ASSERT_FALSE(oneDecimal.isIdentical(one)); - ASSERT_TRUE(oneDecimal.isIdentical(oneDecimal)); - } + const SafeNum oneDecimal(Decimal128(1)); + ASSERT_FALSE(oneDecimal.isIdentical(one)); + ASSERT_TRUE(oneDecimal.isIdentical(oneDecimal)); } TEST(Comparison, EquivalenceComparisonNormal) { @@ -119,10 +109,8 @@ TEST(Comparison, EquivalenceComparisonNormal) { ASSERT_EQUALS(oneLong, oneDouble); ASSERT_EQUALS(oneDouble, one); - if (mongo::Decimal128::enabled) { - const SafeNum oneDecimal(Decimal128(1)); - ASSERT_EQUALS(oneDecimal, one); - } + const SafeNum oneDecimal(Decimal128(1)); + ASSERT_EQUALS(oneDecimal, one); } TEST(Comparison, MaxIntInDouble) { @@ -163,18 +151,16 @@ TEST(Addition, UpConvertion) { ASSERT_EQUALS(stillInt64.type(), mongo::NumberLong); ASSERT_EQUALS(stillDouble.type(), mongo::NumberDouble); - if (mongo::Decimal128::enabled) { - const SafeNum zeroDecimal(Decimal128(0)); - ASSERT_EQUALS((zeroInt64 + zeroDecimal).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroInt32 + zeroDecimal).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDouble + zeroDecimal).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDecimal + zeroInt32).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDecimal + zeroInt64).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDecimal + zeroDouble).type(), mongo::NumberDecimal); + const SafeNum zeroDecimal(Decimal128(0)); + ASSERT_EQUALS((zeroInt64 + zeroDecimal).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroInt32 + zeroDecimal).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDouble + zeroDecimal).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDecimal + zeroInt32).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDecimal + zeroInt64).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDecimal + zeroDouble).type(), mongo::NumberDecimal); - const SafeNum stillDecimal(zeroDecimal + zeroDecimal); - ASSERT_EQUALS(stillDecimal.type(), mongo::NumberDecimal); - } + const SafeNum stillDecimal(zeroDecimal + zeroDecimal); + ASSERT_EQUALS(stillDecimal.type(), mongo::NumberDecimal); } TEST(Addition, Overflow32to64) { @@ -259,15 +245,13 @@ TEST(BitAnd, FloatingPointIsIgnored) { ASSERT_FALSE((val_double & val_ll).isValid()); ASSERT_FALSE((val_double & val_double).isValid()); - if (mongo::Decimal128::enabled) { - const SafeNum val_decimal(Decimal128(1)); - ASSERT_FALSE((val_int & val_decimal).isValid()); - ASSERT_FALSE((val_double & val_decimal).isValid()); - ASSERT_FALSE((val_ll & val_decimal).isValid()); - ASSERT_FALSE((val_decimal & val_int).isValid()); - ASSERT_FALSE((val_decimal & val_ll).isValid()); - ASSERT_FALSE((val_decimal & val_double).isValid()); - } + const SafeNum val_decimal(Decimal128(1)); + ASSERT_FALSE((val_int & val_decimal).isValid()); + ASSERT_FALSE((val_double & val_decimal).isValid()); + ASSERT_FALSE((val_ll & val_decimal).isValid()); + ASSERT_FALSE((val_decimal & val_int).isValid()); + ASSERT_FALSE((val_decimal & val_ll).isValid()); + ASSERT_FALSE((val_decimal & val_double).isValid()); } TEST(BitAnd, 32and32) { @@ -313,15 +297,13 @@ TEST(BitOr, FloatingPointIsIgnored) { ASSERT_FALSE((val_double | val_ll).isValid()); ASSERT_FALSE((val_double | val_double).isValid()); - if (mongo::Decimal128::enabled) { - const SafeNum val_decimal(Decimal128(1)); - ASSERT_FALSE((val_decimal | val_int).isValid()); - ASSERT_FALSE((val_decimal | val_double).isValid()); - ASSERT_FALSE((val_decimal | val_ll).isValid()); - ASSERT_FALSE((val_int | val_decimal).isValid()); - ASSERT_FALSE((val_ll | val_decimal).isValid()); - ASSERT_FALSE((val_double | val_decimal).isValid()); - } + const SafeNum val_decimal(Decimal128(1)); + ASSERT_FALSE((val_decimal | val_int).isValid()); + ASSERT_FALSE((val_decimal | val_double).isValid()); + ASSERT_FALSE((val_decimal | val_ll).isValid()); + ASSERT_FALSE((val_int | val_decimal).isValid()); + ASSERT_FALSE((val_ll | val_decimal).isValid()); + ASSERT_FALSE((val_double | val_decimal).isValid()); } TEST(BitOr, 32and32) { @@ -366,15 +348,13 @@ TEST(BitXor, FloatingPointIsIgnored) { ASSERT_FALSE((val_double ^ val_ll).isValid()); ASSERT_FALSE((val_double ^ val_double).isValid()); - if (mongo::Decimal128::enabled) { - const SafeNum val_decimal(Decimal128(1)); - ASSERT_FALSE((val_decimal ^ val_int).isValid()); - ASSERT_FALSE((val_decimal ^ val_ll).isValid()); - ASSERT_FALSE((val_decimal ^ val_double).isValid()); - ASSERT_FALSE((val_int ^ val_decimal).isValid()); - ASSERT_FALSE((val_ll ^ val_decimal).isValid()); - ASSERT_FALSE((val_double ^ val_decimal).isValid()); - } + const SafeNum val_decimal(Decimal128(1)); + ASSERT_FALSE((val_decimal ^ val_int).isValid()); + ASSERT_FALSE((val_decimal ^ val_ll).isValid()); + ASSERT_FALSE((val_decimal ^ val_double).isValid()); + ASSERT_FALSE((val_int ^ val_decimal).isValid()); + ASSERT_FALSE((val_ll ^ val_decimal).isValid()); + ASSERT_FALSE((val_double ^ val_decimal).isValid()); } TEST(BitXor, 32and32) { @@ -463,17 +443,15 @@ TEST(Multiplication, UpConvertion) { ASSERT_EQUALS(stillInt64.type(), mongo::NumberLong); ASSERT_EQUALS(stillDouble.type(), mongo::NumberDouble); - if (mongo::Decimal128::enabled) { - const SafeNum zeroDecimal(Decimal128(0)); - ASSERT_EQUALS((zeroDecimal * zeroInt32).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroInt32 * zeroDecimal).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDecimal * zeroInt64).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroInt64 * zeroDecimal).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDecimal * zeroDouble).type(), mongo::NumberDecimal); - ASSERT_EQUALS((zeroDouble * zeroDecimal).type(), mongo::NumberDecimal); - const SafeNum stillDecimal(zeroDecimal * zeroDecimal); - ASSERT_EQUALS(stillDecimal.type(), mongo::NumberDecimal); - } + const SafeNum zeroDecimal(Decimal128(0)); + ASSERT_EQUALS((zeroDecimal * zeroInt32).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroInt32 * zeroDecimal).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDecimal * zeroInt64).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroInt64 * zeroDecimal).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDecimal * zeroDouble).type(), mongo::NumberDecimal); + ASSERT_EQUALS((zeroDouble * zeroDecimal).type(), mongo::NumberDecimal); + const SafeNum stillDecimal(zeroDecimal * zeroDecimal); + ASSERT_EQUALS(stillDecimal.type(), mongo::NumberDecimal); } TEST(Multiplication, Overflow32to64) { |