Skip to content

Commit 95da8fe

Browse files
committed
Add a libm feature for Float
1 parent f443e17 commit 95da8fe

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ default-features = false
3737
[features]
3838
default = ["std"]
3939
std = ["num-traits/std"]
40+
libm = ["num-traits/libm"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ version = "0.3"
2727
default-features = false
2828
```
2929

30-
Features based on `Float` types are only available when `std` is enabled. Where
31-
possible, `FloatCore` is used instead. Formatting complex numbers only supports
32-
format width when `std` is enabled.
30+
Features based on `Float` types are only available when `std` or `libm` is
31+
enabled. Where possible, `FloatCore` is used instead. Formatting complex
32+
numbers only supports format width when `std` is enabled.
3333

3434
## Releases
3535

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::error::Error;
3232

3333
use num_traits::{Inv, MulAdd, Num, One, Pow, Signed, Zero};
3434

35-
#[cfg(feature = "std")]
35+
#[cfg(any(feature = "std", feature = "libm"))]
3636
use num_traits::float::Float;
3737
use num_traits::float::FloatCore;
3838

@@ -159,7 +159,7 @@ impl<T: Clone + Signed> Complex<T> {
159159
}
160160
}
161161

162-
#[cfg(feature = "std")]
162+
#[cfg(any(feature = "std", feature = "libm"))]
163163
impl<T: Clone + Float> Complex<T> {
164164
/// Calculate |self|
165165
#[inline]
@@ -1604,7 +1604,7 @@ mod test {
16041604
}
16051605
}
16061606

1607-
#[cfg(feature = "std")]
1607+
#[cfg(any(feature = "std", feature = "libm"))]
16081608
mod float {
16091609
use super::*;
16101610
use num_traits::{Float, Pow};
@@ -2265,7 +2265,7 @@ mod test {
22652265
}
22662266

22672267
#[test]
2268-
#[cfg(feature = "std")]
2268+
#[cfg(any(feature = "std", feature = "libm"))]
22692269
fn test_mul_add_float() {
22702270
assert_eq!(_05_05i.mul_add(_05_05i, _0_0i), _05_05i * _05_05i + _0_0i);
22712271
assert_eq!(_05_05i * _05_05i + _0_0i, _05_05i.mul_add(_05_05i, _0_0i));

src/pow.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::Complex;
22

33
use core::ops::Neg;
4-
#[cfg(feature = "std")]
4+
#[cfg(any(feature = "std", feature = "libm"))]
55
use num_traits::Float;
66
use num_traits::{Num, One, Pow};
77

@@ -85,7 +85,7 @@ pow_impl!(u128, i128);
8585

8686
macro_rules! powf_impl {
8787
($F:ty) => {
88-
#[cfg(feature = "std")]
88+
#[cfg(any(feature = "std", feature = "libm"))]
8989
impl<'a, T: Float> Pow<$F> for &'a Complex<T>
9090
where
9191
$F: Into<T>,
@@ -98,7 +98,7 @@ macro_rules! powf_impl {
9898
}
9999
}
100100

101-
#[cfg(feature = "std")]
101+
#[cfg(any(feature = "std", feature = "libm"))]
102102
impl<'a, 'b, T: Float> Pow<&'b $F> for &'a Complex<T>
103103
where
104104
$F: Into<T>,
@@ -111,7 +111,7 @@ macro_rules! powf_impl {
111111
}
112112
}
113113

114-
#[cfg(feature = "std")]
114+
#[cfg(any(feature = "std", feature = "libm"))]
115115
impl<T: Float> Pow<$F> for Complex<T>
116116
where
117117
$F: Into<T>,
@@ -124,7 +124,7 @@ macro_rules! powf_impl {
124124
}
125125
}
126126

127-
#[cfg(feature = "std")]
127+
#[cfg(any(feature = "std", feature = "libm"))]
128128
impl<'b, T: Float> Pow<&'b $F> for Complex<T>
129129
where
130130
$F: Into<T>,
@@ -145,7 +145,7 @@ powf_impl!(f64);
145145
// These blanket impls are OK, because both the target type and the trait parameter would be
146146
// foreign to anyone else trying to implement something that would overlap, raising E0117.
147147

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

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

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

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

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

@@ -175,7 +175,7 @@ impl<T: Float> Pow<Complex<T>> for Complex<T> {
175175
}
176176
}
177177

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

0 commit comments

Comments
 (0)