summaryrefslogtreecommitdiff
path: root/src/mongo/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/platform')
-rw-r--r--src/mongo/platform/atomic_word.h11
-rw-r--r--src/mongo/platform/decimal128.cpp23
-rw-r--r--src/mongo/platform/decimal128.h15
3 files changed, 26 insertions, 23 deletions
diff --git a/src/mongo/platform/atomic_word.h b/src/mongo/platform/atomic_word.h
index c277497b15c..5a7d38ccca7 100644
--- a/src/mongo/platform/atomic_word.h
+++ b/src/mongo/platform/atomic_word.h
@@ -87,9 +87,7 @@ public:
}
/**
- * Gets the current value of this AtomicWord.
- *
- * Has relaxed semantics.
+ * Gets the current value of this AtomicWord using relaxed memory order.
*/
WordType loadRelaxed() const {
return _value.load(std::memory_order_relaxed);
@@ -103,6 +101,13 @@ public:
}
/**
+ * Sets the value of this AtomicWord to "newValue" using relaxed memory order.
+ */
+ void storeRelaxed(WordType newValue) {
+ _value.store(newValue, std::memory_order_relaxed);
+ }
+
+ /**
* Atomically swaps the current value of this with "newValue".
*
* Returns the old value.
diff --git a/src/mongo/platform/decimal128.cpp b/src/mongo/platform/decimal128.cpp
index 0d12479f70a..ef785025b17 100644
--- a/src/mongo/platform/decimal128.cpp
+++ b/src/mongo/platform/decimal128.cpp
@@ -827,36 +827,33 @@ Decimal128 Decimal128::exponential(std::uint32_t* signalingFlags, RoundingMode r
return Decimal128{libraryTypeToValue(current)};
}
-Decimal128 Decimal128::logarithm(RoundingMode roundMode) const {
+Decimal128 Decimal128::naturalLogarithm(RoundingMode roundMode) const {
std::uint32_t throwAwayFlag = 0;
- return logarithm(&throwAwayFlag, roundMode);
+ return naturalLogarithm(&throwAwayFlag, roundMode);
}
-Decimal128 Decimal128::logarithm(std::uint32_t* signalingFlags, RoundingMode roundMode) const {
+Decimal128 Decimal128::naturalLogarithm(std::uint32_t* signalingFlags,
+ RoundingMode roundMode) const {
BID_UINT128 current = decimal128ToLibraryType(_value);
current = bid128_log(current, roundMode, signalingFlags);
return Decimal128{libraryTypeToValue(current)};
}
-Decimal128 Decimal128::logarithm(const Decimal128& other, RoundingMode roundMode) const {
+Decimal128 Decimal128::logarithm(const Decimal128& base, RoundingMode roundMode) const {
std::uint32_t throwAwayFlag = 0;
- if (other.isEqual(Decimal128(2))) {
+ if (base.isEqual(Decimal128(2))) {
BID_UINT128 current = decimal128ToLibraryType(_value);
current = bid128_log2(current, roundMode, &throwAwayFlag);
return Decimal128{libraryTypeToValue(current)};
}
- if (other.isEqual(Decimal128(10))) {
+ if (base.isEqual(Decimal128(10))) {
BID_UINT128 current = decimal128ToLibraryType(_value);
current = bid128_log10(current, roundMode, &throwAwayFlag);
return Decimal128{libraryTypeToValue(current)};
}
- return logarithm(other, &throwAwayFlag);
-}
-
-Decimal128 Decimal128::logarithm(const Decimal128& other,
- std::uint32_t* signalingFlags,
- RoundingMode roundMode) const {
- return logarithm(signalingFlags, roundMode).divide(other);
+ // Logarithm with a generic base is equivalent to `ln(input) / ln(base)`.
+ return naturalLogarithm(&throwAwayFlag, roundMode)
+ .divide(base.naturalLogarithm(&throwAwayFlag, roundMode));
}
Decimal128 Decimal128::modulo(const Decimal128& other) const {
diff --git a/src/mongo/platform/decimal128.h b/src/mongo/platform/decimal128.h
index 64306df0e0c..06a78352546 100644
--- a/src/mongo/platform/decimal128.h
+++ b/src/mongo/platform/decimal128.h
@@ -467,13 +467,14 @@ public:
Decimal128 exponential(RoundingMode roundMode = kRoundTiesToEven) const;
Decimal128 exponential(std::uint32_t* signalingFlags,
RoundingMode roundMode = kRoundTiesToEven) const;
- Decimal128 logarithm(RoundingMode roundMode = kRoundTiesToEven) const;
- Decimal128 logarithm(std::uint32_t* signalingFlags,
- RoundingMode roundMode = kRoundTiesToEven) const;
- Decimal128 logarithm(const Decimal128& other, RoundingMode roundMode = kRoundTiesToEven) const;
- Decimal128 logarithm(const Decimal128& other,
- std::uint32_t* signalingFlags,
- RoundingMode roundMode = kRoundTiesToEven) const;
+ Decimal128 naturalLogarithm(RoundingMode roundMode = kRoundTiesToEven) const;
+ Decimal128 naturalLogarithm(std::uint32_t* signalingFlags,
+ RoundingMode roundMode = kRoundTiesToEven) const;
+ // Calculate the logarithm with the given `base`, using this number as input. Uses fast paths
+ // for base 2 and 10.
+ // TODO SERVER-91935 convert `logarithm` and others to static methods for a more clear
+ // interface.
+ Decimal128 logarithm(const Decimal128& base, RoundingMode roundMode = kRoundTiesToEven) const;
Decimal128 modulo(const Decimal128& other) const;
Decimal128 modulo(const Decimal128& other, std::uint32_t* signalingFlags) const;