Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a libm feature for Float #385

Merged
merged 1 commit into from Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -19,15 +19,15 @@ matrix:
before_script:
- rustup target add $TARGET
script:
- cargo build --verbose --target $TARGET --no-default-features --features "alloc serde rand"
- cargo build --verbose --target $TARGET --no-default-features --features "alloc libm serde rand"
# try a target that doesn't have std at all, nor alloc
- name: "no_std"
rust: 1.31.0
env: TARGET=thumbv6m-none-eabi
before_script:
- rustup target add $TARGET
script:
- cargo build --verbose --target $TARGET --no-default-features
- cargo build --verbose --target $TARGET --no-default-features --features libm
- name: "rustfmt"
rust: 1.31.0
before_script:
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -69,6 +69,11 @@ std = [

alloc = ["num-bigint", "num-rational/bigint"]

libm = [
"num-complex/libm",
"num-traits/libm",
]

rand = [
"num-bigint/rand",
"num-complex/rand",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -50,6 +50,9 @@ The `num-bigint` crate requires the `std` feature, or the `alloc` feature may
be used instead with Rust 1.36 and later. Other sub-crates may also have
limited functionality when used without `std`.

The `libm` feature uses pure-Rust floating point implementations in `no_std`
builds, enabling the `Float` trait and related `Complex` methods.

The `rand` feature enables randomization traits in `num-bigint` and
`num-complex`.

Expand Down
20 changes: 17 additions & 3 deletions ci/test_full.sh
Expand Up @@ -5,15 +5,17 @@ set -ex
echo Testing num on rustc ${TRAVIS_RUST_VERSION}

case "$TRAVIS_RUST_VERSION" in
1.31.*) STD_FEATURES="serde" ;;
*) STD_FEATURES="serde rand" ;;
1.31.*) STD_FEATURES="libm serde" ;;
*) STD_FEATURES="libm serde rand" ;;
esac

case "$TRAVIS_RUST_VERSION" in
1.3[1-5].*) ;;
*) ALLOC_FEATURES="serde rand" ;;
*) ALLOC_FEATURES="libm serde rand" ;;
esac

NO_STD_FEATURES="libm"

# num should build and test everywhere.
cargo build --verbose
cargo test --verbose
Expand Down Expand Up @@ -48,3 +50,15 @@ if test -n "${ALLOC_FEATURES:+true}"; then
cargo build --no-default-features --features="alloc $ALLOC_FEATURES"
cargo test --no-default-features --features="alloc $ALLOC_FEATURES"
fi

if test -n "${NO_STD_FEATURES:+true}"; then
# Each isolated feature should also work everywhere.
for feature in $NO_STD_FEATURES; do
cargo build --verbose --no-default-features --features="$feature"
cargo test --verbose --no-default-features --features="$feature"
done

# test all supported features together
cargo build --no-default-features --features="$NO_STD_FEATURES"
cargo test --no-default-features --features="$NO_STD_FEATURES"
fi
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -72,7 +72,7 @@ pub use num_integer::Integer;

pub use num_iter::{range, range_inclusive, range_step, range_step_inclusive};

#[cfg(feature = "std")]
#[cfg(any(feature = "libm", feature = "std"))]
pub use num_traits::Float;
pub use num_traits::{
abs, abs_sub, cast, checked_pow, clamp, one, pow, signum, zero, Bounded, CheckedAdd,
Expand Down