20#include <xrpl/basics/Number.h>
21#include <xrpl/beast/utility/instrumentation.h>
35#include <boost/multiprecision/cpp_int.hpp>
36using uint128_t = boost::multiprecision::uint128_t;
38using uint128_t = __uint128_t;
84 push(
unsigned d) noexcept;
120 digits_ |= (d & 0x0000'0000'0000'000FULL) << 60;
126 unsigned d = (
digits_ & 0xF000'0000'0000'0000) >> 60;
163 if (
digits_ > 0x5000'0000'0000'0000)
165 if (
digits_ < 0x5000'0000'0000'0000)
212 if (r == 1 || (r == 0 && (
mantissa_ & 1) == 1))
245 "ripple::Number::operator+=(Number) : is normal");
295 if (r == 1 || (r == 0 && (xm & 1) == 1))
326 if (r == 1 || (r == 0 && (xm & 1) == 1))
352static inline unsigned
356 auto q = (u >> 1) + (u >> 2);
366 auto r =
static_cast<unsigned>(u - ((q << 3) + (q << 1)));
368 auto c = (r + 6) >> 4;
386 "ripple::Number::operator*=(Number) : is normal");
403 auto zm = uint128_t(xm) * uint128_t(ym);
417 xm =
static_cast<rep>(zm);
420 if (r == 1 || (r == 0 && (xm & 1) == 1))
436 "Number::multiplication overflow : exponent is " +
442 "ripple::Number::operator*=(Number) : result is normal");
471 const uint128_t f = 100'000'000'000'000'000;
479Number::operator
rep()
const
491 for (; offset < 0; ++offset)
496 for (; offset > 0; --offset)
503 if (r == 1 || (r == 0 && (drops & 1) == 1))
532 bool negative =
false;
541 exponent + 43 > 0,
"ripple::to_string(Number) : minimum exponent");
543 ptrdiff_t
const pad_prefix = 27;
544 ptrdiff_t
const pad_suffix = 23;
550 val.
append(pad_prefix,
'0');
552 val.
append(pad_suffix,
'0');
554 ptrdiff_t
const offset(
exponent + 43);
556 auto pre_from(val.
begin());
557 auto const pre_to(val.
begin() + offset);
559 auto const post_from(val.
begin() + offset);
560 auto post_to(val.
end());
565 pre_from += pad_prefix;
568 post_to >= post_from,
569 "ripple::to_string(Number) : first distance check");
571 pre_from =
std::find_if(pre_from, pre_to, [](
char c) {
return c !=
'0'; });
576 post_to -= pad_suffix;
579 post_to >= post_from,
580 "ripple::to_string(Number) : second distance check");
585 [](
char c) {
return c !=
'0'; })
594 if (pre_from == pre_to)
597 ret.
append(pre_from, pre_to);
599 if (post_to != post_from)
602 ret.
append(post_from, post_to);
618 auto r =
power(f, n / 2);
637 if (f ==
one || d == 1)
647 if (f <
Number{} && d % 2 == 0)
654 auto const di =
static_cast<int>(d);
655 auto ex = [e = e, di = di]()
657 int k = (e >= 0 ? e : e - (di - 1)) / di;
673 auto const D = ((6 * di + 11) * di + 6) * di + 1;
674 auto const a0 = 3 * di * ((2 * di - 3) * di + 1);
675 auto const a1 = 24 * di * (2 * di - 1);
676 auto const a2 = -30 * (di - 1) * di;
693 }
while (r != rm1 && r != rm2);
730 r = (r + f / r) /
Number(2);
731 }
while (r != rm1 && r != rm2);
760 if ((n % 2) == 1 && (d % 2) == 0 && f <
Number{})
void set_negative() noexcept
void push(unsigned d) noexcept
bool is_negative() const noexcept
void set_positive() noexcept
constexpr bool isnormal() const noexcept
Number & operator+=(Number const &x)
static constexpr std::int64_t maxMantissa
static constexpr int maxExponent
Number & operator/=(Number const &x)
static constexpr std::int64_t minMantissa
constexpr int exponent() const noexcept
static thread_local rounding_mode mode_
static constexpr Number max() noexcept
static rounding_mode getround()
Number & operator*=(Number const &x)
static constexpr int minExponent
static rounding_mode setround(rounding_mode mode)
constexpr rep mantissa() const noexcept
constexpr Number()=default
T make_reverse_iterator(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static unsigned divu10(uint128_t &u)
Number power(Number const &f, unsigned n)
std::string to_string(base_uint< Bits, Tag > const &a)
Number root(Number f, unsigned d)
constexpr Number abs(Number x) noexcept