diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2019-06-16 14:43:09 -0400 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2019-06-16 14:43:09 -0400 |
commit | 58df54d9c73b28bddfb2d83014f653f0c06ef44e (patch) | |
tree | 172189ec94c58019f531adaf731cfe31c2ea5346 /src/mongo/platform/decimal128.cpp | |
parent | e039271638d6dba34e5b64834e3f12e87aeb6455 (diff) | |
download | mongo-58df54d9c73b28bddfb2d83014f653f0c06ef44e.tar.gz |
Revert "SERVER-24374 Make Decimal128 integer ctors constexpr"
This reverts commit e039271638d6dba34e5b64834e3f12e87aeb6455.
Diffstat (limited to 'src/mongo/platform/decimal128.cpp')
-rw-r--r-- | src/mongo/platform/decimal128.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/mongo/platform/decimal128.cpp b/src/mongo/platform/decimal128.cpp index a48a310bf74..18d59af7490 100644 --- a/src/mongo/platform/decimal128.cpp +++ b/src/mongo/platform/decimal128.cpp @@ -187,6 +187,15 @@ BID_UINT128 decimal128ToLibraryType(Decimal128::Value value) { } } // namespace +Decimal128::Decimal128(std::int32_t int32Value) + : _value(libraryTypeToValue(bid128_from_int32(int32Value))) {} + +Decimal128::Decimal128(std::int64_t int64Value) + : _value(libraryTypeToValue(bid128_from_int64(int64Value))) {} + +Decimal128::Decimal128(std::uint64_t uint64Value) + : _value(libraryTypeToValue(bid128_from_uint64(uint64Value))) {} + /** * Quantize a doubleValue argument to a Decimal128 with exactly 15 digits * of precision. @@ -283,8 +292,8 @@ Decimal128::Decimal128(double doubleValue, // Check if the quantization was done correctly: _value stores exactly 15 // decimal digits of precision (15 digits can fit into the low 64 bits of the decimal) - std::uint64_t kSmallest15DigitInt = 1E14; // A 1 with 14 zeros - std::uint64_t kLargest15DigitInt = 1E15 - 1; // 15 nines + uint64_t kSmallest15DigitInt = 1E14; // A 1 with 14 zeros + uint64_t kLargest15DigitInt = 1E15 - 1; // 15 nines if (getCoefficientLow() > kLargest15DigitInt) { // If we didn't precisely get 15 digits of precision, the original base 10 exponent // guess was 1 off, so quantize once more with base10Exp + 1 @@ -315,6 +324,10 @@ Decimal128::Decimal128(std::string stringValue, _value = libraryTypeToValue(dec128); } +Decimal128::Value Decimal128::getValue() const { + return _value; +} + Decimal128 Decimal128::toAbs() const { BID_UINT128 dec128 = decimal128ToLibraryType(_value); dec128 = bid128_abs(dec128); @@ -448,12 +461,12 @@ std::int32_t Decimal128::toInt(std::uint32_t* signalingFlags, RoundingMode round } } -std::int64_t Decimal128::toLong(RoundingMode roundMode) const { +int64_t Decimal128::toLong(RoundingMode roundMode) const { std::uint32_t throwAwayFlag = 0; return toLong(&throwAwayFlag, roundMode); } -std::int64_t Decimal128::toLong(std::uint32_t* signalingFlags, RoundingMode roundMode) const { +int64_t Decimal128::toLong(std::uint32_t* signalingFlags, RoundingMode roundMode) const { BID_UINT128 dec128 = decimal128ToLibraryType(_value); switch (roundMode) { case kRoundTiesToEven: @@ -900,10 +913,10 @@ Decimal128 Decimal128::quantize(const Decimal128& reference, auto normalizedThis = this->normalize(); auto normalizedReferenceExponent = - static_cast<std::int32_t>(reference.normalize().getBiasedExponent()); + static_cast<int32_t>(reference.normalize().getBiasedExponent()); if (normalizedReferenceExponent != 0 && - (static_cast<std::int32_t>(normalizedThis.getBiasedExponent()) - - normalizedReferenceExponent) > 33) { + (static_cast<int32_t>(normalizedThis.getBiasedExponent()) - normalizedReferenceExponent) > + 33) { return normalizedThis; } return nonNormalizingQuantize(reference, signalingFlags, roundMode); @@ -976,7 +989,7 @@ const std::uint64_t t17 = 100ull * 1000 * 1000 * 1000 * 1000 * 1000; // Computed by running the calculations in Python, and verified with static_assert. const std::uint64_t t34lo64 = 4003012203950112767ULL; #if defined(__GNUC__) -MONGO_STATIC_ASSERT(t34lo64 == t17 * t17 - 1); +static_assert(t34lo64 == t17 * t17 - 1, "precomputed constant is wrong"); #endif // Mod t17 by 2^32 to get the low 32 bits of t17's binary representation const std::uint64_t t17lo32 = t17 % (1ull << 32); @@ -1001,7 +1014,7 @@ const Decimal128 Decimal128::kSmallestNegative(1, 0, 0, 1); // Get the representation of 0 (0E0). const Decimal128 Decimal128::kNormalizedZero(Decimal128::Value( - {0, static_cast<std::uint64_t>(Decimal128::kExponentBias) << Decimal128::kExponentFieldPos})); + {0, static_cast<uint64_t>(Decimal128::kExponentBias) << Decimal128::kExponentFieldPos})); // Shift the format of the combination bits to the right position to get Inf and NaN // +Inf = 0111 1000 ... ... = 0x78 ... ..., -Inf = 1111 1000 ... ... = 0xf8 ... ... |