1#include <xrpl/protocol/STNumber.h>
3#include <xrpl/basics/Number.h>
4#include <xrpl/beast/core/LexicalCast.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/protocol/Rules.h>
7#include <xrpl/protocol/SField.h>
8#include <xrpl/protocol/STAmount.h>
9#include <xrpl/protocol/STBase.h>
10#include <xrpl/protocol/STIssue.h>
11#include <xrpl/protocol/Serializer.h>
13#include <boost/lexical_cast.hpp>
14#include <boost/regex.hpp>
32 auto mantissa = sit.
geti64();
33 auto exponent = sit.
geti32();
56 "STNumber::associateAsset",
65 XRPL_ASSERT(
getFName().isBinary(),
"xrpl::STNumber::add : field is binary");
68 "xrpl::STNumber::add : field type match");
85 "xrpl::STNumber::add",
86 "value is already rounded");
99 "xrpl::STNumber::add",
100 "STNumber only used with large mantissa scale");
108 "xrpl::STNumber::add",
109 "mantissa in valid range");
135 return emplace(n, buf, std::move(*
this));
143 "xrpl::STNumber::isEquivalent : field type match");
163 static boost::regex
const reNumber(
168 "([eE]([+-]?)([0-9]+))?"
170 boost::regex_constants::optimize);
174 if (!boost::regex_match(number,
match, reNumber))
175 Throw<std::runtime_error>(
"'" + number +
"' is not a number");
187 bool negative = (
match[1].matched && (
match[1] ==
"-"));
192 if (!
match[4].matched)
200 mantissa = boost::lexical_cast<std::uint64_t>(
match[2] +
match[4]);
201 exponent = -(
match[4].length());
204 if (
match[5].matched)
213 return {mantissa, exponent, negative};
223 if (value.
asInt() >= 0)
243 "xrpld::numberFromJson",
244 "Not in a Transactor context");
254 Throw<std::runtime_error>(
"not a number");
UInt asAbsUInt() const
Correct absolute value from int or unsigned int.
std::string asString() const
Returns the unquoted string value.
Number is a floating point type that can represent a wide range of values.
constexpr rep mantissa() const noexcept
Returns the mantissa of the external view of the Number.
constexpr int exponent() const noexcept
Returns the exponent of the external view of the Number.
static MantissaRange::mantissa_scale getMantissaScale()
Returns which mantissa scale is currently in use for normalization.
A type which can be exported to a well known binary format.
SField const & getFName() const
static STBase * emplace(std::size_t n, void *buf, T &&val)
virtual SerializedTypeID getSType() const
void add(Serializer &s) const override
bool isDefault() const override
void associateAsset(Asset const &a) override
void setValue(Number const &v)
std::string getText() const override
bool isEquivalent(STBase const &t) const override
STBase * move(std::size_t n, void *buf) override
SerializedTypeID getSType() const override
STBase * copy(std::size_t n, void *buf) const override
Number const & value() const
Intermediate class for any STBase-derived class to store an Asset.
virtual void associateAsset(Asset const &a)
std::optional< Asset > asset_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
NumberParts partsFromString(std::string const &number)
std::string to_string(base_uint< Bits, Tag > const &a)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
std::optional< Rules > const & getCurrentTransactionRules()
void roundToAsset(A const &asset, Number &value)
Round an arbitrary precision Number IN PLACE to the precision of a given Asset.
STNumber numberFromJson(SField const &field, Json::Value const &value)