Skip to content

Commit ef2d4ed

Browse files
committed
f no-std
1 parent 607e13e commit ef2d4ed

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
@@ -1019,6 +1019,12 @@ const PRECISION_LOWER_BOUND_DENOMINATOR: u64 = approx::LOWER_BITS_BOUND;
10191019
const AMOUNT_PENALTY_DIVISOR: u64 = 1 << 20;
10201020
const BASE_AMOUNT_PENALTY_DIVISOR: u64 = 1 << 30;
10211021

1022+
/// Raises three `f64`s to the 3rd power, without `powi` because it requires `std` (dunno why).
1023+
#[inline(always)]
1024+
fn three_f64_pow_3(a: f64, b: f64, c: f64) -> (f64, f64, f64) {
1025+
(a * a * a, b * b * b, c * c * c)
1026+
}
1027+
10221028
/// Given liquidity bounds, calculates the success probability (in the form of a numerator and
10231029
/// denominator) of an HTLC. This is a key assumption in our scoring models.
10241030
///
@@ -1055,9 +1061,9 @@ fn success_probability(
10551061
// calculate the cumulative density function between the min/max bounds trivially. Note
10561062
// that we don't bother to normalize the CDF to total to 1, as it will come out in the
10571063
// division of num / den.
1058-
let max_pow = (max - 0.5).powi(3);
1059-
let num = max_pow - (amount - 0.5).powi(3);
1060-
let den = max_pow - (min - 0.5).powi(3);
1064+
let (max_pow, amt_pow, min_pow) = three_f64_pow_3(max - 0.5, amount - 0.5, min - 0.5);
1065+
let num = max_pow - amt_pow;
1066+
let den = max_pow - min_pow;
10611067

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

0 commit comments

Comments
 (0)