Skip to content

Commit 111734b

Browse files
bors[bot]cuviper
andauthored
Merge #385
385: Add a libm feature for Float r=cuviper a=cuviper Co-authored-by: Josh Stone <[email protected]>
2 parents 5d6f64d + 71b674a commit 111734b

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎.travis.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ matrix:
1919
before_script:
2020
- rustup target add $TARGET
2121
script:
22-
- cargo build --verbose --target $TARGET --no-default-features --features "alloc serde rand"
22+
- cargo build --verbose --target $TARGET --no-default-features --features "alloc libm serde rand"
2323
# try a target that doesn't have std at all, nor alloc
2424
- name: "no_std"
2525
rust: 1.31.0
2626
env: TARGET=thumbv6m-none-eabi
2727
before_script:
2828
- rustup target add $TARGET
2929
script:
30-
- cargo build --verbose --target $TARGET --no-default-features
30+
- cargo build --verbose --target $TARGET --no-default-features --features libm
3131
- name: "rustfmt"
3232
rust: 1.31.0
3333
before_script:

‎Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ std = [
6969

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

72+
libm = [
73+
"num-complex/libm",
74+
"num-traits/libm",
75+
]
76+
7277
rand = [
7378
"num-bigint/rand",
7479
"num-complex/rand",

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ The `num-bigint` crate requires the `std` feature, or the `alloc` feature may
5050
be used instead with Rust 1.36 and later. Other sub-crates may also have
5151
limited functionality when used without `std`.
5252

53+
The `libm` feature uses pure-Rust floating point implementations in `no_std`
54+
builds, enabling the `Float` trait and related `Complex` methods.
55+
5356
The `rand` feature enables randomization traits in `num-bigint` and
5457
`num-complex`.
5558

‎ci/test_full.sh‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ set -ex
55
echo Testing num on rustc ${TRAVIS_RUST_VERSION}
66

77
case "$TRAVIS_RUST_VERSION" in
8-
1.31.*) STD_FEATURES="serde" ;;
9-
*) STD_FEATURES="serde rand" ;;
8+
1.31.*) STD_FEATURES="libm serde" ;;
9+
*) STD_FEATURES="libm serde rand" ;;
1010
esac
1111

1212
case "$TRAVIS_RUST_VERSION" in
1313
1.3[1-5].*) ;;
14-
*) ALLOC_FEATURES="serde rand" ;;
14+
*) ALLOC_FEATURES="libm serde rand" ;;
1515
esac
1616

17+
NO_STD_FEATURES="libm"
18+
1719
# num should build and test everywhere.
1820
cargo build --verbose
1921
cargo test --verbose
@@ -48,3 +50,15 @@ if test -n "${ALLOC_FEATURES:+true}"; then
4850
cargo build --no-default-features --features="alloc $ALLOC_FEATURES"
4951
cargo test --no-default-features --features="alloc $ALLOC_FEATURES"
5052
fi
53+
54+
if test -n "${NO_STD_FEATURES:+true}"; then
55+
# Each isolated feature should also work everywhere.
56+
for feature in $NO_STD_FEATURES; do
57+
cargo build --verbose --no-default-features --features="$feature"
58+
cargo test --verbose --no-default-features --features="$feature"
59+
done
60+
61+
# test all supported features together
62+
cargo build --no-default-features --features="$NO_STD_FEATURES"
63+
cargo test --no-default-features --features="$NO_STD_FEATURES"
64+
fi

‎src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub use num_integer::Integer;
7272

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

75-
#[cfg(feature = "std")]
75+
#[cfg(any(feature = "libm", feature = "std"))]
7676
pub use num_traits::Float;
7777
pub use num_traits::{
7878
abs, abs_sub, cast, checked_pow, clamp, one, pow, signum, zero, Bounded, CheckedAdd,

0 commit comments

Comments
 (0)