mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 04:25:51 +00:00
Add implicit conversion from STAmount to Number
This commit is contained in:
committed by
Elliot Lee
parent
24fe5f9fd0
commit
c9c54c9799
@@ -325,7 +325,7 @@ Number::operator*=(Number const& y)
|
|||||||
std::to_string(xe));
|
std::to_string(xe));
|
||||||
mantissa_ = xm * zn;
|
mantissa_ = xm * zn;
|
||||||
exponent_ = xe;
|
exponent_ = xe;
|
||||||
assert(isnormal());
|
assert(isnormal() || *this == Number{});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,8 +362,9 @@ Number::operator/=(Number const& y)
|
|||||||
static_assert(a2.isnormal());
|
static_assert(a2.isnormal());
|
||||||
Number rm2{};
|
Number rm2{};
|
||||||
Number rm1{};
|
Number rm1{};
|
||||||
Number r = a2;
|
Number r = (a2 * d + a1) * d + a0;
|
||||||
r = (a2 * d + a1) * d + a0;
|
// Newton–Raphson iteration of 1/x - d with initial guess r
|
||||||
|
// halt when r stops changing, checking for bouncing on the last iteration
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
rm2 = rm1;
|
rm2 = rm1;
|
||||||
@@ -376,7 +377,7 @@ Number::operator/=(Number const& y)
|
|||||||
|
|
||||||
Number::operator rep() const
|
Number::operator rep() const
|
||||||
{
|
{
|
||||||
std::int64_t drops = mantissa_;
|
rep drops = mantissa_;
|
||||||
int offset = exponent_;
|
int offset = exponent_;
|
||||||
guard g;
|
guard g;
|
||||||
if (drops != 0)
|
if (drops != 0)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <ripple/basics/CountedObject.h>
|
#include <ripple/basics/CountedObject.h>
|
||||||
#include <ripple/basics/IOUAmount.h>
|
#include <ripple/basics/IOUAmount.h>
|
||||||
#include <ripple/basics/LocalValue.h>
|
#include <ripple/basics/LocalValue.h>
|
||||||
|
#include <ripple/basics/Number.h>
|
||||||
#include <ripple/basics/XRPAmount.h>
|
#include <ripple/basics/XRPAmount.h>
|
||||||
#include <ripple/protocol/Issue.h>
|
#include <ripple/protocol/Issue.h>
|
||||||
#include <ripple/protocol/SField.h>
|
#include <ripple/protocol/SField.h>
|
||||||
@@ -144,6 +145,7 @@ public:
|
|||||||
// Legacy support for new-style amounts
|
// Legacy support for new-style amounts
|
||||||
STAmount(IOUAmount const& amount, Issue const& issue);
|
STAmount(IOUAmount const& amount, Issue const& issue);
|
||||||
STAmount(XRPAmount const& amount);
|
STAmount(XRPAmount const& amount);
|
||||||
|
operator Number() const;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
@@ -370,6 +372,13 @@ inline STAmount::operator bool() const noexcept
|
|||||||
return *this != beast::zero;
|
return *this != beast::zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline STAmount::operator Number() const
|
||||||
|
{
|
||||||
|
if (mIsNative)
|
||||||
|
return xrp();
|
||||||
|
return iou();
|
||||||
|
}
|
||||||
|
|
||||||
inline STAmount& STAmount::operator=(beast::Zero)
|
inline STAmount& STAmount::operator=(beast::Zero)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|||||||
@@ -37,11 +37,12 @@ using namespace std::chrono_literals;
|
|||||||
boost::filesystem::path
|
boost::filesystem::path
|
||||||
ShardArchiveHandler::getDownloadDirectory(Config const& config)
|
ShardArchiveHandler::getDownloadDirectory(Config const& config)
|
||||||
{
|
{
|
||||||
return get(config.section(ConfigSection::shardDatabase()),
|
return boost::filesystem::path{
|
||||||
"download_path",
|
|
||||||
get(config.section(ConfigSection::shardDatabase()),
|
get(config.section(ConfigSection::shardDatabase()),
|
||||||
"path",
|
"download_path",
|
||||||
"")) /
|
get(config.section(ConfigSection::shardDatabase()),
|
||||||
|
"path",
|
||||||
|
""))} /
|
||||||
"download";
|
"download";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <ripple/basics/IOUAmount.h>
|
#include <ripple/basics/IOUAmount.h>
|
||||||
#include <ripple/basics/Number.h>
|
#include <ripple/basics/Number.h>
|
||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
|
#include <ripple/protocol/STAmount.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -124,6 +125,10 @@ public:
|
|||||||
BEAST_EXPECT((y == Number{5, 6}));
|
BEAST_EXPECT((y == Number{5, 6}));
|
||||||
IOUAmount z{y};
|
IOUAmount z{y};
|
||||||
BEAST_EXPECT(x == z);
|
BEAST_EXPECT(x == z);
|
||||||
|
XRPAmount xrp{500};
|
||||||
|
STAmount st = xrp;
|
||||||
|
Number n = st;
|
||||||
|
BEAST_EXPECT(XRPAmount{n} == xrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user