add ratio ceil and floor operators on amount_msat

Changelog-none: add ratio ceil and floor operators on amount_msat

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
This commit is contained in:
Lagrang3 2024-10-23 11:16:30 +01:00 committed by Rusty Russell
parent 4dc1a44cd9
commit 225939a5e3
2 changed files with 16 additions and 0 deletions

View File

@ -516,6 +516,16 @@ double amount_msat_ratio(struct amount_msat a, struct amount_msat b)
return (double)a.millisatoshis / b.millisatoshis;
}
u64 amount_msat_ratio_floor(struct amount_msat a, struct amount_msat b)
{
return a.millisatoshis / b.millisatoshis;
}
u64 amount_msat_ratio_ceil(struct amount_msat a, struct amount_msat b)
{
return (a.millisatoshis + b.millisatoshis - 1) / b.millisatoshis;
}
struct amount_msat amount_msat_div(struct amount_msat msat, u64 div)
{
msat.millisatoshis /= div;

View File

@ -148,6 +148,12 @@ bool amount_msat_eq_sat(struct amount_msat msat, struct amount_sat sat);
/* a / b */
double amount_msat_ratio(struct amount_msat a, struct amount_msat b);
/* floor(a/b) */
u64 amount_msat_ratio_floor(struct amount_msat a, struct amount_msat b);
/* ceil(a/b) */
u64 amount_msat_ratio_ceil(struct amount_msat a, struct amount_msat b);
/* min(a,b) and max(a,b) */
static inline struct amount_msat amount_msat_min(struct amount_msat a,
struct amount_msat b)