Skip to content

Commit 6b9604c

Browse files
committed
Update to rand 0.5
1 parent cfede8a commit 6b9604c

6 files changed

Lines changed: 40 additions & 17 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: rust
22
rust:
33
- 1.15.0
4-
- 1.20.0
5-
- 1.25.0
4+
- 1.22.0
5+
- 1.26.0
66
- stable
77
- beta
88
- nightly

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
build = "build.rs"
1515

1616
[package.metadata.docs.rs]
17-
features = ["std"]
17+
features = ["std", "serde", "rand"]
1818

1919
[dependencies]
2020

@@ -29,7 +29,7 @@ default-features = false
2929

3030
[dependencies.rand]
3131
optional = true
32-
version = "0.4"
32+
version = "0.5"
3333
default-features = false
3434

3535
[features]

ci/rustup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/sh
22
# Use rustup to locally run the same suite of tests as .travis.yml.
3-
# (You should first install/update 1.15.0, stable, beta, and nightly.)
3+
# (You should first install/update all versions listed below.)
44

55
set -ex
66

77
export TRAVIS_RUST_VERSION
8-
for TRAVIS_RUST_VERSION in 1.15.0 1.20.0 1.25.0 stable beta nightly; do
8+
for TRAVIS_RUST_VERSION in 1.15.0 1.22.0 1.26.0 stable beta nightly; do
99
run="rustup run $TRAVIS_RUST_VERSION"
1010
$run cargo build --verbose
1111
$run $PWD/ci/test_full.sh

ci/test_full.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ set -ex
44

55
echo Testing num-complex on rustc ${TRAVIS_RUST_VERSION}
66

7-
FEATURES="std rand serde"
8-
if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable)$ ]]; then
7+
FEATURES="std serde"
8+
if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable|1.26|1.22)$ ]]; then
9+
FEATURES="$FEATURES rand"
10+
fi
11+
if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable|1.26)$ ]]; then
912
FEATURES="$FEATURES i128"
1013
fi
1114

src/crand.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Rand implementations for complex numbers
2+
3+
use Complex;
4+
use rand::distributions::Standard;
5+
use rand::prelude::*;
6+
use traits::Num;
7+
8+
impl<T> Distribution<Complex<T>> for Standard
9+
where
10+
T: Num + Clone,
11+
Standard: Distribution<T>,
12+
{
13+
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Complex<T> {
14+
Complex::new(self.sample(rng), self.sample(rng))
15+
}
16+
}
17+
18+
#[test]
19+
fn standard_f64() {
20+
let mut rng = SmallRng::from_seed([42; 16]);
21+
for _ in 0..100 {
22+
let c: Complex<f64> = rng.gen();
23+
assert!(c.re >= 0.0 && c.re < 1.0);
24+
assert!(c.im >= 0.0 && c.im < 1.0);
25+
}
26+
}

src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ use traits::{Zero, One, Num, Inv};
4545
use traits::float::Float;
4646
use traits::float::FloatCore;
4747

48+
#[cfg(feature = "rand")]
49+
mod crand;
50+
4851
// FIXME #1284: handle complex NaN & infinity etc. This
4952
// probably doesn't map to C's _Complex correctly.
5053

@@ -1161,15 +1164,6 @@ impl<'de, T> serde::Deserialize<'de> for Complex<T> where
11611164
}
11621165
}
11631166

1164-
#[cfg(feature = "rand")]
1165-
impl<T> rand::Rand for Complex<T> where
1166-
T: rand::Rand + Num + Clone
1167-
{
1168-
fn rand<R:rand::Rng>(rng: &mut R) -> Self {
1169-
Self::new(rng.gen::<T>(), rng.gen::<T>())
1170-
}
1171-
}
1172-
11731167
#[derive(Debug, PartialEq)]
11741168
pub struct ParseComplexError<E>
11751169
{

0 commit comments

Comments
 (0)