1#include <xrpl/basics/Number.h>
2#include <xrpl/beast/core/LexicalCast.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/protocol/SField.h>
5#include <xrpl/protocol/STBase.h>
6#include <xrpl/protocol/STNumber.h>
7#include <xrpl/protocol/Serializer.h>
9#include <boost/lexical_cast.hpp>
10#include <boost/regex.hpp>
20 :
STBase(field), value_(value)
28 auto mantissa = sit.
geti64();
29 auto exponent = sit.
geti32();
48 XRPL_ASSERT(
getFName().isBinary(),
"xrpl::STNumber::add : field is binary");
51 "xrpl::STNumber::add : field type match");
77 return emplace(n, buf, std::move(*
this));
85 "xrpl::STNumber::isEquivalent : field type match");
105 static boost::regex
const reNumber(
110 "([eE]([+-]?)([0-9]+))?"
112 boost::regex_constants::optimize);
116 if (!boost::regex_match(number,
match, reNumber))
117 Throw<std::runtime_error>(
"'" + number +
"' is not a number");
129 bool negative = (
match[1].matched && (
match[1] ==
"-"));
134 if (!
match[4].matched)
142 mantissa = boost::lexical_cast<std::uint64_t>(
match[2] +
match[4]);
143 exponent = -(
match[4].length());
146 if (
match[5].matched)
155 return {mantissa, exponent, negative};
165 if (value.
asInt() >= 0)
184 Throw<std::range_error>(
"too high");
188 Throw<std::runtime_error>(
"not a number");
193 mantissa = -mantissa;
UInt asAbsUInt() const
Correct absolute value from int or unsigned int.
std::string asString() const
Returns the unquoted string value.
constexpr rep mantissa() const noexcept
constexpr int exponent() const noexcept
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 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
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)
STNumber numberFromJson(SField const &field, Json::Value const &value)