Skip to content

Commit 741c4d9

Browse files
bors[bot]cuviper
andauthored
73: Add a libm feature for Float r=cuviper a=cuviper 74: char::is_whitespace is available even in core now r=cuviper a=cuviper Co-authored-by: Josh Stone <cuviper@gmail.com>
3 parents f443e17 + bfcd391 + b4b91d4 commit 741c4d9

File tree

6 files changed

+22
-40
lines changed

6 files changed

+22
-40
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ matrix:
1818
before_script:
1919
- rustup target add $TARGET
2020
script:
21-
- cargo build --verbose --target $TARGET --no-default-features --features rand,serde
21+
- cargo build --verbose --target $TARGET --no-default-features --features libm,rand,serde
2222
- name: "rustfmt"
2323
rust: 1.31.0
2424
before_script:

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

ci/test_full.sh

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

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

1212
# num-complex should build and test everywhere.

src/lib.rs

Lines changed: 6 additions & 25 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]
@@ -1269,25 +1269,6 @@ where
12691269
F: Fn(&str) -> Result<T, E>,
12701270
T: Clone + Num,
12711271
{
1272-
#[cfg(not(feature = "std"))]
1273-
#[inline]
1274-
fn is_whitespace(c: char) -> bool {
1275-
match c {
1276-
' ' | '\x09'..='\x0d' => true,
1277-
_ if c > '\x7f' => match c {
1278-
'\u{0085}' | '\u{00a0}' | '\u{1680}' => true,
1279-
'\u{2000}'..='\u{200a}' => true,
1280-
'\u{2028}' | '\u{2029}' | '\u{202f}' | '\u{205f}' => true,
1281-
'\u{3000}' => true,
1282-
_ => false,
1283-
},
1284-
_ => false,
1285-
}
1286-
}
1287-
1288-
#[cfg(feature = "std")]
1289-
let is_whitespace = char::is_whitespace;
1290-
12911272
let imag = match s.rfind('j') {
12921273
None => 'i',
12931274
_ => 'j',
@@ -1304,8 +1285,8 @@ where
13041285
// ignore '+'/'-' if part of an exponent
13051286
if (c == b'+' || c == b'-') && !(p == b'e' || p == b'E') {
13061287
// trim whitespace around the separator
1307-
a = &s[..=i].trim_right_matches(is_whitespace);
1308-
b = &s[i + 2..].trim_left_matches(is_whitespace);
1288+
a = &s[..=i].trim_right_matches(char::is_whitespace);
1289+
b = &s[i + 2..].trim_left_matches(char::is_whitespace);
13091290
neg_b = c == b'-';
13101291

13111292
if b.is_empty() || (neg_b && b.starts_with('-')) {
@@ -1604,7 +1585,7 @@ mod test {
16041585
}
16051586
}
16061587

1607-
#[cfg(feature = "std")]
1588+
#[cfg(any(feature = "std", feature = "libm"))]
16081589
mod float {
16091590
use super::*;
16101591
use num_traits::{Float, Pow};
@@ -2265,7 +2246,7 @@ mod test {
22652246
}
22662247

22672248
#[test]
2268-
#[cfg(feature = "std")]
2249+
#[cfg(any(feature = "std", feature = "libm"))]
22692250
fn test_mul_add_float() {
22702251
assert_eq!(_05_05i.mul_add(_05_05i, _0_0i), _05_05i * _05_05i + _0_0i);
22712252
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)