Skip to content
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
8 changes: 8 additions & 0 deletions src/libcore/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ impl f32: num::Num {
static pure fn from_int(n: int) -> f32 { return n as f32; }
}

impl f32: num::Zero {
static pure fn zero() -> f32 { 0.0 }
}

impl f32: num::One {
static pure fn one() -> f32 { 1.0 }
}

//
// Local Variables:
// mode: rust
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ impl f64: num::Num {
static pure fn from_int(n: int) -> f64 { return n as f64; }
}

impl f64: num::Zero {
static pure fn zero() -> f64 { 0.0 }
}

impl f64: num::One {
static pure fn one() -> f64 { 1.0 }
}

//
// Local Variables:
// mode: rust
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ impl float: num::Num {
static pure fn from_int(&self, n: int) -> float { return n as float; }
}

impl float: num::Zero {
static pure fn zero() -> float { 0.0 }
}

impl float: num::One {
static pure fn one() -> float { 1.0 }
}

#[test]
pub fn test_from_str() {
assert from_str(~"3") == Some(3.);
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ impl T: num::Num {
static pure fn from_int(n: int) -> T { return n as T; }
}

impl T: num::Zero {
static pure fn zero() -> T { 0 }
}

impl T: num::One {
static pure fn one() -> T { 1 }
}

impl T: iter::Times {
#[inline(always)]
#[doc = "A convenience form for basic iteration. Given a variable `x` \
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ pub trait Num {
pure fn to_int(&self) -> int;
static pure fn from_int(n: int) -> self;
}

pub trait Zero {
static pure fn zero() -> self;
}

pub trait One {
static pure fn one() -> self;
}
8 changes: 8 additions & 0 deletions src/libcore/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ impl T: num::Num {
static pure fn from_int(n: int) -> T { return n as T; }
}

impl T: num::Zero {
static pure fn zero() -> T { 0 }
}

impl T: num::One {
static pure fn one() -> T { 1 }
}

impl T: iter::Times {
#[inline(always)]
#[doc = "A convenience form for basic iteration. Given a variable `x` \
Expand Down