mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve XRP_t support for Number
- Use the same type of validation as for double
This commit is contained in:
@@ -295,10 +295,19 @@ struct XRP_t
|
||||
return {TOut{v} * dropsPerXRP};
|
||||
}
|
||||
|
||||
/** Returns an amount of XRP as PrettyAmount,
|
||||
which is trivially convertable to STAmount
|
||||
|
||||
@param v The Number of XRP (not drops). May be fractional.
|
||||
*/
|
||||
PrettyAmount
|
||||
operator()(Number v) const
|
||||
{
|
||||
return static_cast<int64_t>(v * dropsPerXRP);
|
||||
auto const c = dropsPerXRP.drops();
|
||||
auto const d = std::int64_t(v * c);
|
||||
if (Number(d) / c != v)
|
||||
Throw<std::domain_error>("unrepresentable");
|
||||
return {d};
|
||||
}
|
||||
|
||||
PrettyAmount
|
||||
|
||||
Reference in New Issue
Block a user