3#include <xrpl/beast/utility/instrumentation.h>
24 while (value >= 10 && value % 10 == 0)
92 return 1'000'000'000'000'000ULL;
94 return 1'000'000'000'000'000'000ULL;
221 static_assert(
maxRep == 9'223'372'036'854'775'807);
257 operator+() const noexcept;
259 operator-() const noexcept;
270 operator+=(
Number const& x);
272 operator-=(
Number const& x);
275 operator*=(
Number const& x);
277 operator/=(
Number const& x);
292 operator
rep() const;
294 friend constexpr
bool
297 return x.negative_ == y.negative_ && x.mantissa_ == y.mantissa_ && x.exponent_ == y.exponent_;
300 friend constexpr bool
306 friend constexpr bool
311 bool const lneg = x.negative_;
312 bool const rneg = y.negative_;
319 if (x.mantissa_ == 0)
320 return y.mantissa_ > 0;
323 if (y.mantissa_ == 0)
327 if (x.exponent_ > y.exponent_)
329 if (x.exponent_ < y.exponent_)
333 return x.mantissa_ < y.mantissa_;
346 friend constexpr
bool
352 friend constexpr bool
358 friend constexpr bool
430 template <Integral64 T>
448 static_assert(
largeRange.
min == 1'000'000'000'000'000'000ULL);
528 :
Number(mantissa < 0, externalToInternal(mantissa), exponent,
normalized{})
549 "xrpl::Number::mantissa",
550 "large normalized mantissa has no remainder");
570 "xrpl::Number::exponent",
571 "large normalized mantissa has no remainder");
684 return *
this ==
Number{} ||
689template <Integral64 T>
698 XRPL_ASSERT_PARTS(!negative,
"xrpl::Number::normalizeToRange",
"Number is non-negative for unsigned range.");
701 auto const sign = negative ? -1 : 1;
717power(Number
const& f,
unsigned n);
724root(Number f,
unsigned d);
732power(Number
const& f,
unsigned n,
unsigned d);
736inline constexpr Number
Sets the new scale and restores the old scale when it leaves scope.
NumberMantissaScaleGuard(MantissaRange::mantissa_scale scale) noexcept
MantissaRange::mantissa_scale const saved_
NumberMantissaScaleGuard(NumberMantissaScaleGuard const &)=delete
~NumberMantissaScaleGuard()
NumberMantissaScaleGuard & operator=(NumberMantissaScaleGuard const &)=delete
NumberRoundModeGuard & operator=(NumberRoundModeGuard const &)=delete
NumberRoundModeGuard(NumberRoundModeGuard const &)=delete
NumberRoundModeGuard(Number::rounding_mode mode) noexcept
saveNumberRoundMode saved_
Number is a floating point type that can represent a wide range of values.
friend constexpr bool operator<(Number const &x, Number const &y) noexcept
static constexpr Number oneSmall()
oneSmall is needed because the ranges are private
static rounding_mode getround()
static internalrep minMantissa()
constexpr rep mantissa() const noexcept
Returns the mantissa of the external view of the Number.
static rounding_mode setround(rounding_mode mode)
static void normalize(bool &negative, T &mantissa, int &exponent, internalrep const &minMantissa, internalrep const &maxMantissa)
Normalize Number components to an arbitrary range.
Number truncate() const noexcept
friend std::string to_string(Number const &amount)
static constexpr MantissaRange smallRange
std::pair< T, int > normalizeToRange(T minMantissa, T maxMantissa) const
friend void doNormalize(bool &negative, T &mantissa_, int &exponent_, MantissaRange::rep const &minMantissa, MantissaRange::rep const &maxMantissa)
static constexpr internalrep maxRep
constexpr Number operator-() const noexcept
MantissaRange::rep internalrep
static Number max() noexcept
static thread_local rounding_mode mode_
static constexpr int minExponent
constexpr Number operator+() const noexcept
Number shiftExponent(int exponentDelta) const
friend constexpr bool operator!=(Number const &x, Number const &y) noexcept
static void setMantissaScale(MantissaRange::mantissa_scale scale)
Changes which mantissa scale is used for normalization.
friend constexpr bool operator>=(Number const &x, Number const &y) noexcept
static internalrep externalToInternal(rep mantissa)
static internalrep maxMantissa()
bool isnormal() const noexcept
constexpr int exponent() const noexcept
Returns the exponent of the external view of the Number.
static constexpr int maxExponent
friend std::ostream & operator<<(std::ostream &os, Number const &x)
static thread_local std::reference_wrapper< MantissaRange const > range_
friend Number root2(Number f)
constexpr int signum() const noexcept
Return the sign of the amount.
Number & operator-=(Number const &x)
static MantissaRange::mantissa_scale getMantissaScale()
Returns which mantissa scale is currently in use for normalization.
static Number min() noexcept
static constexpr MantissaRange largeRange
constexpr Number()=default
static constexpr Number oneLarge()
oneLarge is needed because the ranges are private
static Number lowest() noexcept
friend constexpr bool operator<=(Number const &x, Number const &y) noexcept
friend Number root(Number f, unsigned d)
Number::rounding_mode mode_
saveNumberRoundMode(Number::rounding_mode mode) noexcept
saveNumberRoundMode(saveNumberRoundMode const &)=delete
saveNumberRoundMode & operator=(saveNumberRoundMode const &)=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static std::int64_t constexpr minMantissa
constexpr base_uint< Bits, Tag > operator+(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Number operator-(Number const &x, Number const &y)
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
std::string to_string(base_uint< Bits, Tag > const &a)
static constexpr Number numZero
Number operator/(Number const &x, Number const &y)
Number root(Number f, unsigned d)
Number power(Number const &f, unsigned n)
Number operator*(Number const &x, Number const &y)
constexpr std::optional< int > logTen(T value)
static std::int64_t constexpr maxMantissa
constexpr bool isPowerOfTen(T value)
constexpr Number abs(Number x) noexcept
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
constexpr Number squelch(Number const &x, Number const &limit) noexcept
MantissaRange defines a range for the mantissa of a normalized Number.
constexpr MantissaRange(mantissa_scale scale_)
static constexpr rep getMin(mantissa_scale scale_)