1#include <xrpl/basics/Number.h>
2#include <xrpl/beast/utility/instrumentation.h>
16#pragma message("Using boost::multiprecision::uint128_t")
17#include <boost/multiprecision/cpp_int.hpp>
18using uint128_t = boost::multiprecision::uint128_t;
20using uint128_t = __uint128_t;
66 push(
unsigned d) noexcept;
102 digits_ |= (d & 0x0000'0000'0000'000FULL) << 60;
108 unsigned d = (
digits_ & 0xF000'0000'0000'0000) >> 60;
145 if (
digits_ > 0x5000'0000'0000'0000)
147 if (
digits_ < 0x5000'0000'0000'0000)
194 if (r == 1 || (r == 0 && (
mantissa_ & 1) == 1))
227 "ripple::Number::operator+=(Number) : is normal");
277 if (r == 1 || (r == 0 && (xm & 1) == 1))
308 if (r == 1 || (r == 0 && (xm & 1) == 1))
334static inline unsigned
338 auto q = (u >> 1) + (u >> 2);
348 auto r =
static_cast<unsigned>(u - ((q << 3) + (q << 1)));
350 auto c = (r + 6) >> 4;
368 "ripple::Number::operator*=(Number) : is normal");
385 auto zm = uint128_t(xm) * uint128_t(ym);
399 xm =
static_cast<rep>(zm);
402 if (r == 1 || (r == 0 && (xm & 1) == 1))
418 "Number::multiplication overflow : exponent is " +
424 "ripple::Number::operator*=(Number) : result is normal");
453 uint128_t
const f = 100'000'000'000'000'000;
461Number::operator
rep()
const
473 for (; offset < 0; ++offset)
478 for (; offset > 0; --offset)
485 if (r == 1 || (r == 0 && (drops & 1) == 1))
514 bool negative =
false;
523 exponent + 43 > 0,
"ripple::to_string(Number) : minimum exponent");
525 ptrdiff_t
const pad_prefix = 27;
526 ptrdiff_t
const pad_suffix = 23;
532 val.
append(pad_prefix,
'0');
534 val.
append(pad_suffix,
'0');
536 ptrdiff_t
const offset(
exponent + 43);
538 auto pre_from(val.
begin());
539 auto const pre_to(val.
begin() + offset);
541 auto const post_from(val.
begin() + offset);
542 auto post_to(val.
end());
547 pre_from += pad_prefix;
550 post_to >= post_from,
551 "ripple::to_string(Number) : first distance check");
553 pre_from =
std::find_if(pre_from, pre_to, [](
char c) {
return c !=
'0'; });
558 post_to -= pad_suffix;
561 post_to >= post_from,
562 "ripple::to_string(Number) : second distance check");
567 [](
char c) {
return c !=
'0'; })
576 if (pre_from == pre_to)
579 ret.
append(pre_from, pre_to);
581 if (post_to != post_from)
584 ret.
append(post_from, post_to);
600 auto r =
power(f, n / 2);
619 if (f ==
one || d == 1)
629 if (f <
Number{} && d % 2 == 0)
636 auto const di =
static_cast<int>(d);
637 auto ex = [e = e, di = di]()
639 int k = (e >= 0 ? e : e - (di - 1)) / di;
655 auto const D = ((6 * di + 11) * di + 6) * di + 1;
656 auto const a0 = 3 * di * ((2 * di - 3) * di + 1);
657 auto const a1 = 24 * di * (2 * di - 1);
658 auto const a2 = -30 * (di - 1) * di;
675 }
while (r != rm1 && r != rm2);
712 r = (r + f / r) /
Number(2);
713 }
while (r != rm1 && r != rm2);
742 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