diff --git a/.travis.yml b/.travis.yml index a4650dd..428599e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: before_script: - rustup target add $TARGET script: - - cargo build --verbose --target $TARGET --no-default-features --features rand,serde + - cargo build --verbose --target $TARGET --no-default-features --features libm,rand,serde - name: "rustfmt" rust: 1.31.0 before_script: diff --git a/Cargo.toml b/Cargo.toml index 36c5305..5163eb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,4 @@ default-features = false [features] default = ["std"] std = ["num-traits/std"] +libm = ["num-traits/libm"] diff --git a/README.md b/README.md index 28d0a00..fe8f183 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ version = "0.3" default-features = false ``` -Features based on `Float` types are only available when `std` is enabled. Where -possible, `FloatCore` is used instead. Formatting complex numbers only supports -format width when `std` is enabled. +Features based on `Float` types are only available when `std` or `libm` is +enabled. Where possible, `FloatCore` is used instead. Formatting complex +numbers only supports format width when `std` is enabled. ## Releases diff --git a/ci/test_full.sh b/ci/test_full.sh index cd95543..ca71bbf 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -5,8 +5,8 @@ set -ex echo Testing num-complex on rustc ${TRAVIS_RUST_VERSION} case "$TRAVIS_RUST_VERSION" in - 1.31.*) FEATURES="serde" ;; - *) FEATURES="serde rand" ;; + 1.31.*) FEATURES="libm serde" ;; + *) FEATURES="libm serde rand" ;; esac # num-complex should build and test everywhere. diff --git a/src/lib.rs b/src/lib.rs index beb6795..343f752 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ use std::error::Error; use num_traits::{Inv, MulAdd, Num, One, Pow, Signed, Zero}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::float::Float; use num_traits::float::FloatCore; @@ -159,7 +159,7 @@ impl Complex { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] impl Complex { /// Calculate |self| #[inline] @@ -1604,7 +1604,7 @@ mod test { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] mod float { use super::*; use num_traits::{Float, Pow}; @@ -2265,7 +2265,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] fn test_mul_add_float() { assert_eq!(_05_05i.mul_add(_05_05i, _0_0i), _05_05i * _05_05i + _0_0i); assert_eq!(_05_05i * _05_05i + _0_0i, _05_05i.mul_add(_05_05i, _0_0i)); diff --git a/src/pow.rs b/src/pow.rs index c48ebb7..569f01d 100644 --- a/src/pow.rs +++ b/src/pow.rs @@ -1,7 +1,7 @@ use super::Complex; use core::ops::Neg; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; use num_traits::{Num, One, Pow}; @@ -85,7 +85,7 @@ pow_impl!(u128, i128); macro_rules! powf_impl { ($F:ty) => { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] impl<'a, T: Float> Pow<$F> for &'a Complex where $F: Into, @@ -98,7 +98,7 @@ macro_rules! powf_impl { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] impl<'a, 'b, T: Float> Pow<&'b $F> for &'a Complex where $F: Into, @@ -111,7 +111,7 @@ macro_rules! powf_impl { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] impl Pow<$F> for Complex where $F: Into, @@ -124,7 +124,7 @@ macro_rules! powf_impl { } } - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] impl<'b, T: Float> Pow<&'b $F> for Complex where $F: Into, @@ -145,7 +145,7 @@ powf_impl!(f64); // These blanket impls are OK, because both the target type and the trait parameter would be // foreign to anyone else trying to implement something that would overlap, raising E0117. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] impl<'a, T: Float> Pow> for &'a Complex { type Output = Complex; @@ -155,7 +155,7 @@ impl<'a, T: Float> Pow> for &'a Complex { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] impl<'a, 'b, T: Float> Pow<&'b Complex> for &'a Complex { type Output = Complex; @@ -165,7 +165,7 @@ impl<'a, 'b, T: Float> Pow<&'b Complex> for &'a Complex { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] impl Pow> for Complex { type Output = Complex; @@ -175,7 +175,7 @@ impl Pow> for Complex { } } -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] impl<'b, T: Float> Pow<&'b Complex> for Complex { type Output = Complex;