mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Division rounds towards zero automatically. We don't need to do anything
special in mulRound or divRound before we divide if we're rounding towards zero.
This commit is contained in:
@@ -231,10 +231,8 @@ STAmount STAmount::mulRound(const STAmount& v1, const STAmount& v2,
|
||||
if ((BN_add_word64(&v, value1) != 1) || (BN_mul_word64(&v, value2) != 1))
|
||||
throw std::runtime_error("internal bn error");
|
||||
|
||||
if (resultNegative != roundUp)
|
||||
if (resultNegative != roundUp) // rounding down is automatic when we divide
|
||||
BN_add_word64(&v, tenTo14m1);
|
||||
else
|
||||
BN_sub_word64(&v, tenTo14m1);
|
||||
|
||||
if (BN_div_word64(&v, tenTo14) == ((uint64) -1))
|
||||
throw std::runtime_error("internal bn error");
|
||||
@@ -273,16 +271,17 @@ STAmount STAmount::divRound(const STAmount& num, const STAmount& den,
|
||||
--denOffset;
|
||||
}
|
||||
|
||||
cLog(lsINFO) << "num: " << numVal << " " << numOffset;
|
||||
cLog(lsINFO) << "den: " << denVal << " " << denOffset;
|
||||
|
||||
bool resultNegative = num.mIsNegative != num.mIsNegative;
|
||||
// Compute (numerator * 10^17) / denominator
|
||||
CBigNum v;
|
||||
if ((BN_add_word64(&v, numVal) != 1) || (BN_mul_word64(&v, tenTo17) != 1))
|
||||
throw std::runtime_error("internal bn error");
|
||||
|
||||
if (resultNegative != roundUp)
|
||||
if (resultNegative != roundUp) // Rounding down is automatic when we divide
|
||||
BN_add_word64(&v, denVal - 1);
|
||||
else
|
||||
BN_sub_word64(&v, denVal - 1);
|
||||
|
||||
if (BN_div_word64(&v, denVal) == ((uint64) -1))
|
||||
throw std::runtime_error("internal bn error");
|
||||
|
||||
Reference in New Issue
Block a user