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 #73

Merged
merged 2 commits 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
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -37,3 +37,4 @@ default-features = false
[features]
default = ["std"]
std = ["num-traits/std"]
libm = ["num-traits/libm"]
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions ci/test_full.sh
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -159,7 +159,7 @@ impl<T: Clone + Signed> Complex<T> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
impl<T: Clone + Float> Complex<T> {
/// Calculate |self|
#[inline]
Expand Down Expand Up @@ -1604,7 +1604,7 @@ mod test {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
mod float {
use super::*;
use num_traits::{Float, Pow};
Expand Down Expand Up @@ -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));
Expand Down
18 changes: 9 additions & 9 deletions 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};

Expand Down Expand Up @@ -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<T>
where
$F: Into<T>,
Expand All @@ -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<T>
where
$F: Into<T>,
Expand All @@ -111,7 +111,7 @@ macro_rules! powf_impl {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
impl<T: Float> Pow<$F> for Complex<T>
where
$F: Into<T>,
Expand All @@ -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<T>
where
$F: Into<T>,
Expand All @@ -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<Complex<T>> for &'a Complex<T> {
type Output = Complex<T>;

Expand All @@ -155,7 +155,7 @@ impl<'a, T: Float> Pow<Complex<T>> for &'a Complex<T> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
impl<'a, 'b, T: Float> Pow<&'b Complex<T>> for &'a Complex<T> {
type Output = Complex<T>;

Expand All @@ -165,7 +165,7 @@ impl<'a, 'b, T: Float> Pow<&'b Complex<T>> for &'a Complex<T> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
impl<T: Float> Pow<Complex<T>> for Complex<T> {
type Output = Complex<T>;

Expand All @@ -175,7 +175,7 @@ impl<T: Float> Pow<Complex<T>> for Complex<T> {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "libm"))]
impl<'b, T: Float> Pow<&'b Complex<T>> for Complex<T> {
type Output = Complex<T>;

Expand Down