20#include <xrpl/basics/Number.h>
21#include <xrpl/beast/utility/instrumentation.h>
35#pragma message("Using boost::multiprecision::uint128_t")
36#include <boost/multiprecision/cpp_int.hpp>
37using uint128_t = boost::multiprecision::uint128_t;
39using uint128_t = __uint128_t;
85 push(
unsigned d) noexcept;
121 digits_ |= (d & 0x0000'0000'0000'000FULL) << 60;
127 unsigned d = (
digits_ & 0xF000'0000'0000'0000) >> 60;
164 if (
digits_ > 0x5000'0000'0000'0000)
166 if (
digits_ < 0x5000'0000'0000'0000)
213 if (r == 1 || (r == 0 && (
mantissa_ & 1) == 1))
246 "ripple::Number::operator+=(Number) : is normal");
296 if (r == 1 || (r == 0 && (xm & 1) == 1))
327 if (r == 1 || (r == 0 && (xm & 1) == 1))
353static inline unsigned
357 auto q = (u >> 1) + (u >> 2);
367 auto r =
static_cast<unsigned>(u - ((q << 3) + (q << 1)));
369 auto c = (r + 6) >> 4;
387 "ripple::Number::operator*=(Number) : is normal");
404 auto zm = uint128_t(xm) * uint128_t(ym);
418 xm =
static_cast<rep>(zm);
421 if (r == 1 || (r == 0 && (xm & 1) == 1))
437 "Number::multiplication overflow : exponent is " +
443 "ripple::Number::operator*=(Number) : result is normal");
472 uint128_t
const f = 100'000'000'000'000'000;
480Number::operator
rep()
const
492 for (; offset < 0; ++offset)
497 for (; offset > 0; --offset)
504 if (r == 1 || (r == 0 && (
drops & 1) == 1))
533 bool negative =
false;
542 exponent + 43 > 0,
"ripple::to_string(Number) : minimum exponent");
544 ptrdiff_t
const pad_prefix = 27;
545 ptrdiff_t
const pad_suffix = 23;
551 val.
append(pad_prefix,
'0');
553 val.
append(pad_suffix,
'0');
555 ptrdiff_t
const offset(
exponent + 43);
557 auto pre_from(val.
begin());
558 auto const pre_to(val.
begin() + offset);
560 auto const post_from(val.
begin() + offset);
561 auto post_to(val.
end());
566 pre_from += pad_prefix;
569 post_to >= post_from,
570 "ripple::to_string(Number) : first distance check");
572 pre_from =
std::find_if(pre_from, pre_to, [](
char c) {
return c !=
'0'; });
577 post_to -= pad_suffix;
580 post_to >= post_from,
581 "ripple::to_string(Number) : second distance check");
586 [](
char c) {
return c !=
'0'; })
595 if (pre_from == pre_to)
598 ret.
append(pre_from, pre_to);
600 if (post_to != post_from)
603 ret.
append(post_from, post_to);
619 auto r =
power(f, n / 2);
638 if (f ==
one || d == 1)
648 if (f <
Number{} && d % 2 == 0)
655 auto const di =
static_cast<int>(d);
656 auto ex = [e = e, di = di]()
658 int k = (e >= 0 ? e : e - (di - 1)) / di;
674 auto const D = ((6 * di + 11) * di + 6) * di + 1;
675 auto const a0 = 3 * di * ((2 * di - 3) * di + 1);
676 auto const a1 = 24 * di * (2 * di - 1);
677 auto const a2 = -30 * (di - 1) * di;
694 }
while (r != rm1 && r != rm2);
731 r = (r + f / r) /
Number(2);
732 }
while (r != rm1 && r != rm2);
761 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)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
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