mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
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:
parent
4dc1a44cd9
commit
225939a5e3
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user