1#include <xrpl/protocol/IOUAmount.h>
3#include <xrpl/basics/Number.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/protocol/STAmount.h>
73 if (other == beast::kZero)
76 if (*
this == beast::kZero)
95 using namespace boost::multiprecision;
103 static auto const kPowerTable = [] {
107 for (
int i = 0; i < 30; ++i)
117 static auto kLoG10Floor = [](uint128_t
const& v) {
129 static auto kLoG10Ceil = [](uint128_t
const& v) {
138 bool const neg = amt.
mantissa() < 0;
139 uint128_t
const den128(den);
142 uint128_t
const mul = uint128_t(neg ? -amt.
mantissa() : amt.
mantissa()) * uint128_t(num);
144 auto low = mul / den128;
145 uint128_t rem(mul - low * den128);
157 auto const roomToGrow = kFl64 - kLoG10Ceil(low);
160 exponent -= roomToGrow;
161 low *= kPowerTable[roomToGrow];
162 rem *= kPowerTable[roomToGrow];
164 auto const addRem = rem / den128;
166 rem = rem - addRem * den128;
173 bool hasRem = bool(rem);
174 auto const mustShrink = kLoG10Ceil(low) - kFl64;
177 uint128_t
const sav(low);
178 exponent += mustShrink;
179 low /= kPowerTable[mustShrink];
181 hasRem = bool(sav - low * kPowerTable[mustShrink]);
Floating point representation of amounts with high dynamic range.
IOUAmount & operator+=(IOUAmount const &other)
mantissa_type mantissa() const noexcept
exponent_type exponent() const noexcept
static IOUAmount fromNumber(Number const &number)
static IOUAmount minPositiveAmount()
void normalize()
Adjusts the mantissa and exponent to the proper range.
Number is a floating point type that can represent a wide range of values.
std::pair< T, int > normalizeToRange() const
static constexpr int kMinOffset
static constexpr std::uint64_t kMinValue
static constexpr std::uint64_t kMaxValue
static constexpr int kMaxOffset
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static constexpr int kMinExponent
static constexpr std::int64_t kMinMantissa
std::string to_string(BaseUInt< Bits, Tag > const &a)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
static constexpr std::int64_t kMaxMantissa
static constexpr int kMaxExponent
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)