Skip to content

Commit 5edaec2

Browse files
HowardHinnantintelliot
authored andcommitted
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.
1 parent 2f1f453 commit 5edaec2

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/ripple/basics/Number.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Number
8181
Number&
8282
operator/=(Number const& x);
8383

84+
static constexpr Number
85+
min() noexcept;
86+
static constexpr Number
87+
max() noexcept;
88+
static constexpr Number
89+
lowest() noexcept;
90+
8491
explicit operator XRPAmount() const; // round to nearest, even on tie
8592
explicit operator rep() const; // round to nearest, even on tie
8693

@@ -290,6 +297,24 @@ operator/(Number const& x, Number const& y)
290297
return z;
291298
}
292299

300+
inline constexpr Number
301+
Number::min() noexcept
302+
{
303+
return Number{minMantissa, minExponent, unchecked{}};
304+
}
305+
306+
inline constexpr Number
307+
Number::max() noexcept
308+
{
309+
return Number{maxMantissa, maxExponent, unchecked{}};
310+
}
311+
312+
inline constexpr Number
313+
Number::lowest() noexcept
314+
{
315+
return -Number{maxMantissa, maxExponent, unchecked{}};
316+
}
317+
293318
inline constexpr bool
294319
Number::isnormal() const noexcept
295320
{

src/ripple/basics/impl/IOUAmount.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ IOUAmount::normalize()
5353

5454
if (*stNumberSwitchover)
5555
{
56-
const Number v{mantissa_, exponent_};
56+
Number const v{mantissa_, exponent_};
5757
mantissa_ = v.mantissa();
5858
exponent_ = v.exponent();
5959
if (exponent_ > maxExponent)

src/ripple/protocol/Feature.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,9 @@ extern uint256 const featureNonFungibleTokensV1_1;
340340
extern uint256 const fixTrustLinesToSelf;
341341
extern uint256 const fixRemoveNFTokenAutoTrustLine;
342342
extern uint256 const featureImmediateOfferKilled;
343-
<<<<<<< HEAD
344343
extern uint256 const featureDisallowIncoming;
345344
extern uint256 const featureXRPFees;
346-
=======
347345
extern uint256 const fixUniversalNumber;
348-
>>>>>>> Use Number for IOUAmount and STAmount arithmetic
349346

350347
} // namespace ripple
351348

0 commit comments

Comments
 (0)