Skip to content

Commit 6471eb0

Browse files
committed
Depend on libm in no-std for powf(64)
In the next commits we'll need `f64`'s `powf`, which is only available in `std`. For `no-std`, here we depend on `libm` (a `rust-lang` org project), which we can use for `powf`.
1 parent 9856fb6 commit 6471eb0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lightning/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ unsafe_revoked_tx_signing = []
3131
# Override signing to not include randomness when generating signatures for test vectors.
3232
_test_vectors = []
3333

34-
no-std = ["hashbrown", "bitcoin/no-std", "core2/alloc"]
34+
no-std = ["hashbrown", "bitcoin/no-std", "core2/alloc", "libm"]
3535
std = ["bitcoin/std"]
3636

3737
# Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases
@@ -48,6 +48,7 @@ regex = { version = "1.5.6", optional = true }
4848
backtrace = { version = "0.3", optional = true }
4949

5050
core2 = { version = "0.3.0", optional = true, default-features = false }
51+
libm = { version = "0.2", optional = true, default-features = false }
5152

5253
[dev-dependencies]
5354
regex = "1.5.6"

lightning/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern crate hex;
6969
#[cfg(any(test, feature = "_test_utils"))] extern crate regex;
7070

7171
#[cfg(not(feature = "std"))] extern crate core2;
72+
#[cfg(not(feature = "std"))] extern crate libm;
7273

7374
#[cfg(ldk_bench)] extern crate criterion;
7475

lightning/src/routing/scoring.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,16 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ScoreUpdate for Prob
14691469
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for ProbabilisticScorerUsingTime<G, L, T>
14701470
where L::Target: Logger {}
14711471

1472+
#[cfg(feature = "std")]
1473+
#[inline]
1474+
fn powf64(n: f64, exp: f64) -> f64 {
1475+
n.powf(exp)
1476+
}
1477+
#[cfg(not(feature = "std"))]
1478+
fn powf64(n: f64, exp: f64) -> f64 {
1479+
libm::powf(n as f32, exp as f32) as f64
1480+
}
1481+
14721482
mod approx {
14731483
const BITS: u32 = 64;
14741484
const HIGHEST_BIT: u32 = BITS - 1;

0 commit comments

Comments
 (0)