3#include <xrpl/basics/Number.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/protocol/Units.h>
9#include <boost/multiprecision/cpp_int.hpp>
10#include <boost/operators.hpp>
19class XRPAmount :
private boost::totally_ordered<XRPAmount>,
20 private boost::additive<XRPAmount>,
21 private boost::equality_comparable<XRPAmount, std::int64_t>,
22 private boost::additive<XRPAmount, std::int64_t>
138 operator bool() const noexcept
165 template <
class Dest>
174 return static_cast<Dest
>(
drops_);
177 template <
class Dest>
181 return dropsAs<Dest>().value_or(defaultValue);
184 template <
class Dest>
188 return dropsAs<Dest>().value_or(defaultValue.
drops());
200 "Expected XRPAmount to be a signed integral type");
246template <
class Char,
class Traits>
250 return os << q.
drops();
262 using namespace boost::multiprecision;
265 Throw<std::runtime_error>(
"division by zero");
267 int128_t
const amt128(amt.
drops());
268 auto const neg = amt.
drops() < 0;
269 auto const m = amt128 * num;
279 Throw<std::overflow_error>(
"XRP mulRatio overflow");
Number is a floating point type that can represent a wide range of values.
static XRPAmount minPositiveAmount()
XRPAmount & operator-=(XRPAmount const &other)
XRPAmount & operator-=(value_type const &rhs)
constexpr XRPAmount(beast::Zero)
XRPAmount & operator+=(value_type const &rhs)
bool operator<(XRPAmount const &other) const
constexpr XRPAmount(value_type drops)
constexpr value_type value() const
Returns the underlying value.
friend std::istream & operator>>(std::istream &s, XRPAmount &val)
Dest dropsAs(XRPAmount defaultValue) const
constexpr value_type drops() const
Returns the number of drops.
constexpr XRPAmount(XRPAmount const &other)=default
XRPAmount(Number const &x)
constexpr XRPAmount operator*(value_type const &rhs) const
bool operator==(XRPAmount const &other) const
bool operator==(value_type other) const
XRPAmount & operator+=(XRPAmount const &other)
Json::Value jsonClipped() const
constexpr XRPAmount & operator=(XRPAmount const &other)=default
Dest dropsAs(Dest defaultValue) const
XRPAmount & operator*=(value_type const &rhs)
constexpr XRPAmount & operator=(beast::Zero)
XRPAmount operator-() const
std::optional< Dest > dropsAs() const
friend constexpr XRPAmount operator*(value_type lhs, XRPAmount const &rhs)
constexpr double decimalXRP() const
XRPAmount & operator=(value_type drops)
constexpr int signum() const noexcept
Return the sign of the amount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
constexpr XRPAmount DROPS_PER_XRP
Number of drops per 1 XRP.
Zero allows classes to offer efficient comparisons to zero.