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>
31 auto mantissa = sit.
geti64();
32 auto exponent = sit.
geti32();
55 "STNumber::associateAsset",
64 XRPL_ASSERT(
getFName().isBinary(),
"xrpl::STNumber::add : field is binary");
65 XRPL_ASSERT(
getFName().fieldType ==
getSType(),
"xrpl::STNumber::add : field type match");
80 XRPL_ASSERT_PARTS(
value_ ==
value,
"xrpl::STNumber::add",
"value is already rounded");
93 "xrpl::STNumber::add",
94 "STNumber only used with large mantissa scale");
102 "xrpl::STNumber::add",
103 "mantissa in valid range");
129 return emplace(n, buf, std::move(*
this));
136 t.
getSType() == this->getSType(),
"xrpl::STNumber::isEquivalent : field type match");
156 static boost::regex
const reNumber(
161 "([eE]([+-]?)([0-9]+))?"
163 boost::regex_constants::optimize);
167 if (!boost::regex_match(number,
match, reNumber))
168 Throw<std::runtime_error>(
"'" + number +
"' is not a number");
180 bool negative = (
match[1].matched && (
match[1] ==
"-"));
185 if (!
match[4].matched)
193 mantissa = boost::lexical_cast<std::uint64_t>(
match[2] +
match[4]);
194 exponent = -(
match[4].length());
197 if (
match[5].matched)
206 return {mantissa, exponent, negative};
216 if (value.
asInt() >= 0)
245 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)