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);
243 explicit constexpr Number(
261 operator+() const noexcept;
263 operator-() const noexcept;
274 operator+=(
Number const& x);
276 operator-=(
Number const& x);
279 operator*=(
Number const& x);
281 operator/=(
Number const& x);
296 operator
rep() const;
298 friend constexpr
bool
301 return x.negative_ == y.negative_ && x.mantissa_ == y.mantissa_ &&
302 x.exponent_ == y.exponent_;
305 friend constexpr bool
311 friend constexpr bool
316 bool const lneg = x.negative_;
317 bool const rneg = y.negative_;
324 if (x.mantissa_ == 0)
325 return y.mantissa_ > 0;
328 if (y.mantissa_ == 0)
332 if (x.exponent_ > y.exponent_)
334 if (x.exponent_ < y.exponent_)
338 return x.mantissa_ < y.mantissa_;
351 friend constexpr
bool
357 friend constexpr bool
363 friend constexpr bool
435 template <Integral64 T>
453 static_assert(
largeRange.
min == 1'000'000'000'000'000'000ULL);
538 :
Number(mantissa < 0, externalToInternal(mantissa), exponent,
normalized{})
559 "xrpl::Number::mantissa",
560 "large normalized mantissa has no remainder");
580 "xrpl::Number::exponent",
581 "large normalized mantissa has no remainder");
694 return *
this ==
Number{} ||
695 (
range.min <= abs_m && abs_m <=
range.max && (abs_m <=
maxRep || abs_m % 10 == 0) &&
699template <Integral64 T>
710 "xrpl::Number::normalizeToRange",
711 "Number is non-negative for unsigned range.");
714 auto const sign = negative ? -1 : 1;
730power(Number
const& f,
unsigned n);
737root(Number f,
unsigned d);
745power(Number
const& f,
unsigned n,
unsigned d);
749inline 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_)