Improve XRP_t support for Number

- Use the same type of validation as for double
This commit is contained in:
Ed Hennis
2025-11-03 21:28:25 -05:00
parent 2b7bb92262
commit f2b13dd69c

View File

@@ -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