mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 13:05:53 +00:00
Use Number for IOUAmount and STAmount arithmetic
* Guarded by amendment fixUniversalNumber * Produces slightly better accuracy in some computations.
This commit is contained in:
committed by
Elliot Lee
parent
48e804c40c
commit
a82ad5ba76
@@ -339,6 +339,19 @@ STAmount::iou() const
|
||||
return {mantissa, exponent};
|
||||
}
|
||||
|
||||
STAmount&
|
||||
STAmount::operator=(IOUAmount const& iou)
|
||||
{
|
||||
assert(mIsNative == false);
|
||||
mOffset = iou.exponent();
|
||||
mIsNegative = iou < beast::zero;
|
||||
if (mIsNegative)
|
||||
mValue = static_cast<std::uint64_t>(-iou.mantissa());
|
||||
else
|
||||
mValue = static_cast<std::uint64_t>(iou.mantissa());
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Operators
|
||||
@@ -382,6 +395,13 @@ operator+(STAmount const& v1, STAmount const& v2)
|
||||
if (v1.native())
|
||||
return {v1.getFName(), getSNValue(v1) + getSNValue(v2)};
|
||||
|
||||
if (*stNumberSwitchover)
|
||||
{
|
||||
auto x = v1;
|
||||
x = v1.iou() + v2.iou();
|
||||
return x;
|
||||
}
|
||||
|
||||
int ov1 = v1.exponent(), ov2 = v2.exponent();
|
||||
std::int64_t vv1 = static_cast<std::int64_t>(v1.mantissa());
|
||||
std::int64_t vv2 = static_cast<std::int64_t>(v2.mantissa());
|
||||
@@ -733,6 +753,12 @@ STAmount::canonicalize()
|
||||
|
||||
mIsNative = false;
|
||||
|
||||
if (*stNumberSwitchover)
|
||||
{
|
||||
*this = iou();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mValue == 0)
|
||||
{
|
||||
mOffset = -100;
|
||||
@@ -1170,6 +1196,9 @@ multiply(STAmount const& v1, STAmount const& v2, Issue const& issue)
|
||||
return STAmount(v1.getFName(), minV * maxV);
|
||||
}
|
||||
|
||||
if (*stNumberSwitchover)
|
||||
return {IOUAmount{Number{v1} * Number{v2}}, issue};
|
||||
|
||||
std::uint64_t value1 = v1.mantissa();
|
||||
std::uint64_t value2 = v2.mantissa();
|
||||
int offset1 = v1.exponent();
|
||||
|
||||
Reference in New Issue
Block a user