20#include <xrpl/basics/Number.h>
21#include <xrpl/beast/core/LexicalCast.h>
22#include <xrpl/beast/utility/instrumentation.h>
23#include <xrpl/protocol/SField.h>
24#include <xrpl/protocol/STBase.h>
25#include <xrpl/protocol/STNumber.h>
26#include <xrpl/protocol/Serializer.h>
28#include <boost/lexical_cast.hpp>
29#include <boost/regex.hpp>
39 :
STBase(field), value_(value)
47 auto mantissa = sit.
geti64();
48 auto exponent = sit.
geti32();
68 getFName().isBinary(),
"ripple::STNumber::add : field is binary");
71 "ripple::STNumber::add : field type match");
97 return emplace(n, buf, std::move(*
this));
105 "ripple::STNumber::isEquivalent : field type match");
125 static boost::regex
const reNumber(
130 "([eE]([+-]?)([0-9]+))?"
132 boost::regex_constants::optimize);
137 Throw<std::runtime_error>(
"'" +
number +
"' is not a number");
149 bool negative = (
match[1].matched && (
match[1] ==
"-"));
154 if (!
match[4].matched)
162 mantissa = boost::lexical_cast<std::uint64_t>(
match[2] +
match[4]);
163 exponent = -(
match[4].length());
166 if (
match[5].matched)
175 return {mantissa, exponent, negative};
185 if (value.
asInt() >= 0)
204 Throw<std::range_error>(
"too high");
208 Throw<std::runtime_error>(
"not a number");
213 mantissa = -mantissa;
std::string asString() const
Returns the unquoted string value.
constexpr int exponent() const noexcept
constexpr rep mantissa() const noexcept
A type which can be exported to a well known binary format.
virtual SerializedTypeID getSType() const
SField const & getFName() const
static STBase * emplace(std::size_t n, void *buf, T &&val)
SerializedTypeID getSType() const override
bool isDefault() const override
void add(Serializer &s) const override
std::string getText() const override
void setValue(Number const &v)
STBase * move(std::size_t n, void *buf) override
Number const & value() const
STBase * copy(std::size_t n, void *buf) const override
bool isEquivalent(STBase const &t) const override
static Number number(STAmount const &a)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
NumberParts partsFromString(std::string const &number)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
STNumber numberFromJson(SField const &field, Json::Value const &value)
std::string to_string(base_uint< Bits, Tag > const &a)