Skip to content

Commit

Permalink
Merge #385
Browse files Browse the repository at this point in the history
385: Add a libm feature for Float r=cuviper a=cuviper



Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
bors[bot] and cuviper authored Jan 21, 2020
2 parents 5d6f64d + 71b674a commit 111734b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 111734b

Please sign in to comment.