Add initial number module implementation
This commit is contained in:
parent
370083e2f0
commit
8fe0bf3f71
1 changed files with 13 additions and 49 deletions
|
@ -6,55 +6,19 @@
|
||||||
///
|
///
|
||||||
/// Scheme numbers are complex, literally.
|
/// Scheme numbers are complex, literally.
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
type Int = i64;
|
||||||
pub struct Number {
|
type Flt = f64;
|
||||||
pub value: f64
|
|
||||||
|
trait Number {
|
||||||
|
fn is_number(&self) -> bool { true }
|
||||||
|
fn is_complex(&self) -> bool { false }
|
||||||
|
fn is_real(&self) -> bool { false }
|
||||||
|
fn is_rational(&self) -> bool { false }
|
||||||
|
fn is_integer(&self) -> bool { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Number {
|
struct Integer(Int);
|
||||||
pub fn from_int(v: i64) -> Number {
|
struct Rational(Int, Int);
|
||||||
Number { value: v as f64 }
|
struct Real(Flt);
|
||||||
}
|
struct Complex<'a>(&'a Number, &'a Number);
|
||||||
|
|
||||||
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 }
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue