Skip to content

Commit 798a706

Browse files
committed
add ratio ceil and floor operators on amount_msat
Changelog-none: add ratio ceil and floor operators on amount_msat Signed-off-by: Lagrang3 <[email protected]>
1 parent 5dc292a commit 798a706

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

common/amount.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,16 @@ double amount_msat_ratio(struct amount_msat a, struct amount_msat b)
516516
return (double)a.millisatoshis / b.millisatoshis;
517517
}
518518

519+
u64 amount_msat_ratio_floor(struct amount_msat a, struct amount_msat b)
520+
{
521+
return a.millisatoshis / b.millisatoshis;
522+
}
523+
524+
u64 amount_msat_ratio_ceil(struct amount_msat a, struct amount_msat b)
525+
{
526+
return (a.millisatoshis + b.millisatoshis - 1) / b.millisatoshis;
527+
}
528+
519529
struct amount_msat amount_msat_div(struct amount_msat msat, u64 div)
520530
{
521531
msat.millisatoshis /= div;

common/amount.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ bool amount_msat_eq_sat(struct amount_msat msat, struct amount_sat sat);
148148
/* a / b */
149149
double amount_msat_ratio(struct amount_msat a, struct amount_msat b);
150150

151+
/* floor(a/b) */
152+
u64 amount_msat_ratio_floor(struct amount_msat a, struct amount_msat b);
153+
154+
/* ceil(a/b) */
155+
u64 amount_msat_ratio_ceil(struct amount_msat a, struct amount_msat b);
156+
151157
/* min(a,b) and max(a,b) */
152158
static inline struct amount_msat amount_msat_min(struct amount_msat a,
153159
struct amount_msat b)

0 commit comments

Comments
 (0)