Skip to content

Commit

Permalink
Introduce min/max observers for Number
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HowardHinnant authored and intelliot committed Feb 7, 2023
1 parent 2f1f453 commit 5edaec2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/ripple/basics/Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ class Number
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

Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/basics/impl/IOUAmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5edaec2

Please sign in to comment.