Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
fix(lib): fix fallout of numeric reform
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Nov 16, 2014
1 parent 7f8c117 commit 866762f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -4,5 +4,5 @@ name = "simplot"
version = "0.0.0"
authors = ["Jorge Aparicio <japaric@linux.com>"]

[dev-dependencies.num]
git = "https://github.com/rust-lang/num"
[dev-dependencies.complex]
git = "https://github.com/japaric/complex.rs"
18 changes: 11 additions & 7 deletions src/lib.rs
Expand Up @@ -5,7 +5,7 @@

use std::collections::TreeMap;
use std::io::{Command, File, IoResult, Process};
use std::num;
use std::num::{Float, mod};
use std::str::{MaybeOwned, mod};

use data::Matrix;
Expand Down Expand Up @@ -177,18 +177,19 @@ impl Figure {
/// ![Plot](multiaxis.svg)
///
/// ```
/// # extern crate num;
/// # extern crate complex;
/// # extern crate simplot;
/// # fn main() {
/// # use std::io::{fs, USER_RWX};
/// use num::Complex;
/// use complex::Complex;
/// use simplot::axis::{BottomX, LeftY, Logarithmic, RightY};
/// use simplot::color::{DarkViolet, Rgb};
/// use simplot::curve::Lines;
/// use simplot::grid::Major;
/// use simplot::key::{Center, Inside, Top};
/// use simplot::{BottomXRightY, Figure, logspace};
/// use std::f64::consts::PI;
/// use std::num::Float;
///
/// fn tf(x: f64) -> Complex<f64> {
/// Complex::new(0., x) / Complex::new(10., x) / Complex::new(1., x / 10_000.)
Expand All @@ -197,7 +198,7 @@ impl Figure {
/// let (start, end) = (1.1, 90_000.);
/// let xs = logspace(start, end, 101);
/// let phase = xs.map(|x| tf(x).arg() * 180. / PI);
/// let magnitude = xs.map(|x| tf(x).norm());
/// let magnitude = xs.map(|x| tf(x).abs());
///
/// # fs::mkdir_recursive(&Path::new("target/doc/simplot"), USER_RWX).unwrap();
/// # assert_eq!(Some(String::new()),
Expand Down Expand Up @@ -351,6 +352,7 @@ impl Figure {
/// use simplot::curve::{Impulses, LinesPoints, Steps};
/// use simplot::key::{Inside, Left, Top};
/// use simplot::{Circle, Dash, Figure, linspace};
/// use std::num::FloatMath;
///
/// let xs = linspace::<f64>(-10., 10., 51);
///
Expand Down Expand Up @@ -429,6 +431,7 @@ impl Figure {
/// use simplot::key::{Outside, Right, Top};
/// use simplot::{Figure, FilledCircle, linspace};
/// use std::f64::consts::PI;
/// use std::num::FloatMath;
/// use std::rand::{Rng, mod};
///
/// fn sinc(mut x: f64) -> f64 {
Expand Down Expand Up @@ -510,6 +513,7 @@ impl Figure {
/// use simplot::{Figure, linspace};
/// use std::f64::consts::PI;
/// use std::iter;
/// use std::num::Float;
///
/// let (start, end) = (-5., 5.);
/// let xs = linspace(start, end, 101);
Expand Down Expand Up @@ -757,7 +761,7 @@ trait Script {
pub fn linspace<T>(start: T, end: T, n: uint) -> Linspace<T> where T: Float {
let step = if n < 2 {
// NB The value of `step` doesn't matter in these cases
num::zero()
Float::zero()
} else {
(end - start) / num::cast(n - 1).unwrap()
};
Expand All @@ -771,13 +775,13 @@ pub fn linspace<T>(start: T, end: T, n: uint) -> Linspace<T> where T: Float {
}

pub fn logspace<T>(start: T, end: T, n: uint) -> Logspace<T> where T: Float {
assert!(start > num::zero() && end > num::zero());
assert!(start > Float::zero() && end > Float::zero());

let (start, end) = (start.ln(), end.ln());

let step = if n < 2 {
// NB The value of `step` doesn't matter in these cases
num::zero()
Float::zero()
} else {
(end - start) / num::cast(n - 1).unwrap()
};
Expand Down

0 comments on commit 866762f

Please sign in to comment.