Introduce min/max observers for Number

Three static member functions are introduced with
definitions consistent with std::numeric_limits:

static constexpr Number min() noexcept;

  Returns: The minimum positive value.  This is the value closest to zero.

static constexpr Number max() noexcept;

  Returns: The maximum possible value.

static constexpr Number lowest() noexcept;

  Returns: The negative value which is less than all other values.
This commit is contained in:
Howard Hinnant
2023-02-01 11:20:13 -05:00
committed by Elliot Lee
parent 2f1f453052
commit 5edaec2bd0
3 changed files with 26 additions and 4 deletions

View File

@@ -81,6 +81,13 @@ public:
Number&
operator/=(Number const& x);
static constexpr Number
min() noexcept;
static constexpr Number
max() noexcept;
static constexpr Number
lowest() noexcept;
explicit operator XRPAmount() const; // round to nearest, even on tie
explicit operator rep() const; // round to nearest, even on tie
@@ -290,6 +297,24 @@ operator/(Number const& x, Number const& y)
return z;
}
inline constexpr Number
Number::min() noexcept
{
return Number{minMantissa, minExponent, unchecked{}};
}
inline constexpr Number
Number::max() noexcept
{
return Number{maxMantissa, maxExponent, unchecked{}};
}
inline constexpr Number
Number::lowest() noexcept
{
return -Number{maxMantissa, maxExponent, unchecked{}};
}
inline constexpr bool
Number::isnormal() const noexcept
{

View File

@@ -53,7 +53,7 @@ IOUAmount::normalize()
if (*stNumberSwitchover)
{
const Number v{mantissa_, exponent_};
Number const v{mantissa_, exponent_};
mantissa_ = v.mantissa();
exponent_ = v.exponent();
if (exponent_ > maxExponent)

View File

@@ -340,12 +340,9 @@ extern uint256 const featureNonFungibleTokensV1_1;
extern uint256 const fixTrustLinesToSelf;
extern uint256 const fixRemoveNFTokenAutoTrustLine;
extern uint256 const featureImmediateOfferKilled;
<<<<<<< HEAD
extern uint256 const featureDisallowIncoming;
extern uint256 const featureXRPFees;
=======
extern uint256 const fixUniversalNumber;
>>>>>>> Use Number for IOUAmount and STAmount arithmetic
} // namespace ripple