Skip to content

Commit 06c6ecf

Browse files
committed
f no-std
1 parent f5b5e8c commit 06c6ecf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lightning/src/routing/scoring.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ const PRECISION_LOWER_BOUND_DENOMINATOR: u64 = approx::LOWER_BITS_BOUND;
10221022
const AMOUNT_PENALTY_DIVISOR: u64 = 1 << 20;
10231023
const BASE_AMOUNT_PENALTY_DIVISOR: u64 = 1 << 30;
10241024

1025+
/// Raises three `f64`s to the 3rd power, without `powi` because it requires `std` (dunno why).
1026+
#[inline(always)]
1027+
fn three_f64_pow_3(a: f64, b: f64, c: f64) -> (f64, f64, f64) {
1028+
(a * a * a, b * b * b, c * c * c)
1029+
}
1030+
10251031
/// Given liquidity bounds, calculates the success probability (in the form of a numerator and
10261032
/// denominator) of an HTLC. This is a key assumption in our scoring models.
10271033
///
@@ -1058,9 +1064,9 @@ fn success_probability(
10581064
// calculate the cumulative density function between the min/max bounds trivially. Note
10591065
// that we don't bother to normalize the CDF to total to 1, as it will come out in the
10601066
// division of num / den.
1061-
let max_pow = (max - 0.5).powi(3);
1062-
let num = max_pow - (amount - 0.5).powi(3);
1063-
let den = max_pow - (min - 0.5).powi(3);
1067+
let (max_pow, amt_pow, min_pow) = three_f64_pow_3(max - 0.5, amount - 0.5, min - 0.5);
1068+
let num = max_pow - amt_pow;
1069+
let den = max_pow - min_pow;
10641070

10651071
// Because our numerator and denominator max out at 0.5^3 we need to multiply them by
10661072
// quite a large factor to get something useful (ideally in the 2^30 range).

0 commit comments

Comments
 (0)