mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Optimize / operation.
This commit is contained in:
@@ -219,24 +219,23 @@ STAmount operator-(STAmount v1, STAmount v2)
|
||||
|
||||
STAmount operator/(const STAmount& num, const STAmount& den)
|
||||
{
|
||||
CBigNum numerator, denominator, quotient;
|
||||
CBigNum v;
|
||||
|
||||
if (den.value == 0) throw std::runtime_error("illegal offer");
|
||||
if (num.value == 0) return STAmount();
|
||||
|
||||
// Compute (numerator * 10^16) / denominator
|
||||
if ((BN_add_word(&numerator, num.value) != 1) ||
|
||||
(BN_add_word(&denominator, den.value) != 1) ||
|
||||
(BN_mul_word(&numerator, 10000000000000000ull) != 1) ||
|
||||
(BN_div("ient, NULL, &numerator, &denominator, CAutoBN_CTX()) != 1))
|
||||
if ((BN_add_word(&v, num.value) != 1) ||
|
||||
(BN_mul_word(&v, 10000000000000000ull) != 1) ||
|
||||
(BN_div_word(&v, den.value) == ((BN_ULONG)-1)))
|
||||
{
|
||||
throw std::runtime_error("internal bn error");
|
||||
}
|
||||
|
||||
// 10^15 <= quotient <= 10^17
|
||||
assert(BN_num_bytes("ient) <= 60);
|
||||
assert(BN_num_bytes(&v) <= 60);
|
||||
|
||||
return STAmount(quotient.getulong(), num.offset - den.offset - 16);
|
||||
return STAmount(v.getulong(), num.offset - den.offset - 16);
|
||||
}
|
||||
|
||||
STAmount operator*(const STAmount &v1, const STAmount &v2)
|
||||
|
||||
Reference in New Issue
Block a user