Skip to content

Compilation failure for no_std & alloc feature #1088

@michael-p

Description

@michael-p

Dear all,

It looks like the rand crate does not compile for no_std targets when the alloc feature is enabled:

$ cargo build --no-default-features --features "alloc"
   Compiling rand_core v0.6.1 (/Users/michaelp/Desktop/rand/rand_core)
   Compiling rand v0.8.2 (/Users/michaelp/Desktop/rand)
error[E0599]: no method named `powf` found for type `f64` in the current scope
   --> src/seq/index.rs:393:40
    |
393 |             let key = rng.gen::<f64>().powf(1.0 / weight);
    |                                        ^^^^ method not found in `f64`

The reason is that f64::powf() and friends are not available in a no_std context.
The two options I see are to either make the functions sample_weighted and sample_efraimidis_spirakis available only when std feature is enabled, or alternatively use the pow function from the libm crate (this is what most other no_std crates like nalgebra use for their math needs).

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions