diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs index 9fbf902170a..5e34c7c5530 100644 --- a/src/libcore/f32.rs +++ b/src/libcore/f32.rs @@ -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 diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs index 86565f9e252..2e35d0360b6 100644 --- a/src/libcore/f64.rs +++ b/src/libcore/f64.rs @@ -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 diff --git a/src/libcore/float.rs b/src/libcore/float.rs index 2ea9c5925ef..27184a39708 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -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.); diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index eed439823fc..c3fe24fff32 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -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` \ diff --git a/src/libcore/num.rs b/src/libcore/num.rs index fed9db8767b..4c2daa458a4 100644 --- a/src/libcore/num.rs +++ b/src/libcore/num.rs @@ -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; +} diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 1a9bca92d1f..80b393a813c 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -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` \