20#include <xrpl/basics/LocalValue.h>
21#include <xrpl/basics/Number.h>
22#include <xrpl/basics/contract.h>
23#include <xrpl/beast/utility/Zero.h>
24#include <xrpl/protocol/IOUAmount.h>
26#include <boost/multiprecision/cpp_int.hpp>
42getStaticSTNumberSwitchover()
44 static LocalValue<bool> r{
true};
52 return *getStaticSTNumberSwitchover();
58 *getStaticSTNumberSwitchover() = v;
89 Throw<std::overflow_error>(
"value overflow");
109 Throw<std::overflow_error>(
"IOUAmount::normalize");
122 Throw<std::overflow_error>(
"value overflow");
129 : mantissa_(other.mantissa()), exponent_(other.exponent())
132 Throw<std::overflow_error>(
"value overflow");
140 if (other == beast::zero)
143 if (*
this == beast::zero)
196 using namespace boost::multiprecision;
199 Throw<std::runtime_error>(
"division by zero");
204 static auto const powerTable = [] {
208 for (
int i = 0; i < 30; ++i)
218 static auto log10Floor = [](uint128_t
const& v) {
231 static auto log10Ceil = [](uint128_t
const& v) {
239 static auto const fl64 =
242 bool const neg = amt.
mantissa() < 0;
243 uint128_t
const den128(den);
246 uint128_t
const mul =
249 auto low = mul / den128;
250 uint128_t rem(mul - low * den128);
262 auto const roomToGrow = fl64 - log10Ceil(low);
265 exponent -= roomToGrow;
266 low *= powerTable[roomToGrow];
267 rem *= powerTable[roomToGrow];
269 auto const addRem = rem / den128;
271 rem = rem - addRem * den128;
278 bool hasRem = bool(rem);
279 auto const mustShrink = log10Ceil(low) - fl64;
282 uint128_t
const sav(low);
283 exponent += mustShrink;
284 low /= powerTable[mustShrink];
286 hasRem = bool(sav - low * powerTable[mustShrink]);
Floating point representation of amounts with high dynamic range.
int exponent() const noexcept
void normalize()
Adjusts the mantissa and exponent to the proper range.
std::int64_t mantissa() const noexcept
IOUAmount & operator+=(IOUAmount const &other)
static IOUAmount minPositiveAmount()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static int constexpr maxExponent
static int constexpr minExponent
static std::int64_t constexpr maxMantissa
static std::int64_t constexpr minMantissa
void setSTNumberSwitchover(bool v)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
std::string to_string(base_uint< Bits, Tag > const &a)
bool getSTNumberSwitchover()