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

fix(lib): fix fallout of numeric reform #10

Merged
merged 1 commit into from
Nov 16, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ name = "simplot"
version = "0.0.0"
authors = ["Jorge Aparicio <[email protected]>"]

[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
Original file line number Diff line number Diff line change
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