summaryrefslogtreecommitdiff
path: root/src/mongo/platform/decimal128.cpp
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-06-14 13:13:21 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2019-06-16 13:10:31 -0400
commite039271638d6dba34e5b64834e3f12e87aeb6455 (patch)
tree426afa8e561b2450ee3d7840c005a587547a99e5 /src/mongo/platform/decimal128.cpp
parent62e3fdae6062cf1fe5e55932eb6aa26f0f593d17 (diff)
downloadmongo-e039271638d6dba34e5b64834e3f12e87aeb6455.tar.gz
SERVER-24374 Make Decimal128 integer ctors constexpr
reverts fab9fde6ba which reverted 668100df79
Diffstat (limited to 'src/mongo/platform/decimal128.cpp')
-rw-r--r--src/mongo/platform/decimal128.cpp31
1 files changed, 9 insertions, 22 deletions
diff --git a/src/mongo/platform/decimal128.cpp b/src/mongo/platform/decimal128.cpp
index 18d59af7490..a48a310bf74 100644
--- a/src/mongo/platform/decimal128.cpp
+++ b/src/mongo/platform/decimal128.cpp
@@ -187,15 +187,6 @@ 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.
@@ -292,8 +283,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)
- uint64_t kSmallest15DigitInt = 1E14; // A 1 with 14 zeros
- uint64_t kLargest15DigitInt = 1E15 - 1; // 15 nines
+ std::uint64_t kSmallest15DigitInt = 1E14; // A 1 with 14 zeros
+ std::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
@@ -324,10 +315,6 @@ 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);
@@ -461,12 +448,12 @@ std::int32_t Decimal128::toInt(std::uint32_t* signalingFlags, RoundingMode round
}
}
-int64_t Decimal128::toLong(RoundingMode roundMode) const {
+std::int64_t Decimal128::toLong(RoundingMode roundMode) const {
std::uint32_t throwAwayFlag = 0;
return toLong(&throwAwayFlag, roundMode);
}
-int64_t Decimal128::toLong(std::uint32_t* signalingFlags, RoundingMode roundMode) const {
+std::int64_t Decimal128::toLong(std::uint32_t* signalingFlags, RoundingMode roundMode) const {
BID_UINT128 dec128 = decimal128ToLibraryType(_value);
switch (roundMode) {
case kRoundTiesToEven:
@@ -913,10 +900,10 @@ Decimal128 Decimal128::quantize(const Decimal128& reference,
auto normalizedThis = this->normalize();
auto normalizedReferenceExponent =
- static_cast<int32_t>(reference.normalize().getBiasedExponent());
+ static_cast<std::int32_t>(reference.normalize().getBiasedExponent());
if (normalizedReferenceExponent != 0 &&
- (static_cast<int32_t>(normalizedThis.getBiasedExponent()) - normalizedReferenceExponent) >
- 33) {
+ (static_cast<std::int32_t>(normalizedThis.getBiasedExponent()) -
+ normalizedReferenceExponent) > 33) {
return normalizedThis;
}
return nonNormalizingQuantize(reference, signalingFlags, roundMode);
@@ -989,7 +976,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__)
-static_assert(t34lo64 == t17 * t17 - 1, "precomputed constant is wrong");
+MONGO_STATIC_ASSERT(t34lo64 == t17 * t17 - 1);
#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);
@@ -1014,7 +1001,7 @@ const Decimal128 Decimal128::kSmallestNegative(1, 0, 0, 1);
// Get the representation of 0 (0E0).
const Decimal128 Decimal128::kNormalizedZero(Decimal128::Value(
- {0, static_cast<uint64_t>(Decimal128::kExponentBias) << Decimal128::kExponentFieldPos}));
+ {0, static_cast<std::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 ... ...