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();
49 getFName().isBinary(),
"ripple::STNumber::add : field is binary");
52 "ripple::STNumber::add : field type match");
78 return emplace(n, buf, std::move(*
this));
86 "ripple::STNumber::isEquivalent : field type match");
106 static boost::regex
const reNumber(
111 "([eE]([+-]?)([0-9]+))?"
113 boost::regex_constants::optimize);
117 if (!boost::regex_match(number,
match, reNumber))
118 Throw<std::runtime_error>(
"'" + number +
"' is not a number");
130 bool negative = (
match[1].matched && (
match[1] ==
"-"));
135 if (!
match[4].matched)
143 mantissa = boost::lexical_cast<std::uint64_t>(
match[2] +
match[4]);
144 exponent = -(
match[4].length());
147 if (
match[5].matched)
156 return {mantissa, exponent, negative};
166 if (value.
asInt() >= 0)
185 Throw<std::range_error>(
"too high");
189 Throw<std::runtime_error>(
"not a number");
194 mantissa = -mantissa;
UInt asAbsUInt() const
Correct absolute value from int or unsigned int.
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
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)