MCPcopy Create free account
hub / github.com/ElementsProject/lightning / amount_msat_mul_div

Function amount_msat_mul_div

common/amount.c:608–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608static bool amount_msat_mul_div(struct amount_msat *res,
609 struct amount_msat msat, u64 mul, u64 div)
610{
611 /* We avoid overflow in the operation (a/b)*x noticing that we can
612 * decompose x = q_x * b + r_x, where q_x = floor(x/b) and
613 * r_x = x mod b, then: x*(a/b) = a*q_x + a*r_x/b, which does not
614 * overflow if a*b does not. */
615 if (mul_overflows_u64(mul, div))
616 return false;
617 u64 x = msat.millisatoshis;
618 res->millisatoshis = mul * (x / div) + (mul * (x % div)) / div;
619 return true;
620}
621
622bool amount_msat_fee(struct amount_msat *fee,
623 struct amount_msat amt,

Callers 2

amount_msat_feeFunction · 0.85
amount_msat_sub_feeFunction · 0.85

Calls 1

mul_overflows_u64Function · 0.85

Tested by

no test coverage detected