Create types module with a module for numbers; move Number there

This commit is contained in:
Eryn Wells 2016-12-29 10:10:40 -05:00
parent 93bdc998bd
commit f799d7642d
5 changed files with 71 additions and 14 deletions

5
src/types/mod.rs Normal file
View file

@ -0,0 +1,5 @@
/* mod.rs
* Eryn Wells <eryn@erynwells.me>
*/
pub mod number;

62
src/types/number.rs Normal file
View file

@ -0,0 +1,62 @@
/* number.rs
* Eryn Wells <eryn@erynwells.me>
*/
/// # Numbers
///
/// Scheme numbers are complex, literally.
#[derive(PartialEq, Debug)]
pub struct Number { value: f64 }
impl Number {
pub fn new() -> Number {
Number { value: 0.0 }
}
pub fn from_int(v: i64) -> Number {
Number { value: v as f64 }
}
pub fn from_float(v: f64) -> Number {
Number { value: v }
}
}
/*
pub trait Number {
fn new() -> Number;
fn from_int(v: i64);
fn from_float(v: f64);
}
pub trait Exact {
fn exact() -> bool;
}
type Integer = i64;
impl Exact for Integer {
fn exact() -> bool { true }
}
#[derive(PartialEq, Debug)]
pub struct Rational { numer: i64, denom: i64 }
impl Exact for Rational {
fn exact() -> bool { true }
}
type Real = f64;
impl Exact for Real {
fn exact() -> bool { false }
}
#[derive(PartialEq, Debug)]
pub struct Complex { real: f64, imag: f64 }
impl Exact for Complex {
fn exact() -> bool { false }
}
*/