File tree Expand file tree Collapse file tree 6 files changed +48
-0
lines changed Expand file tree Collapse file tree 6 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,14 @@ impl f32: num::Num {
174
174
static pure fn from_int( n: int ) -> f32 { return n as f32 ; }
175
175
}
176
176
177
+ impl f32 : num:: Zero {
178
+ static pure fn zero( ) -> f32 { 0.0 }
179
+ }
180
+
181
+ impl f32 : num:: One {
182
+ static pure fn one( ) -> f32 { 1.0 }
183
+ }
184
+
177
185
//
178
186
// Local Variables:
179
187
// mode: rust
Original file line number Diff line number Diff line change @@ -193,6 +193,14 @@ impl f64: num::Num {
193
193
static pure fn from_int( n: int ) -> f64 { return n as f64 ; }
194
194
}
195
195
196
+ impl f64 : num:: Zero {
197
+ static pure fn zero( ) -> f64 { 0.0 }
198
+ }
199
+
200
+ impl f64 : num:: One {
201
+ static pure fn one( ) -> f64 { 1.0 }
202
+ }
203
+
196
204
//
197
205
// Local Variables:
198
206
// mode: rust
Original file line number Diff line number Diff line change @@ -443,6 +443,14 @@ impl float: num::Num {
443
443
static pure fn from_int( & self , n: int ) -> float { return n as float ; }
444
444
}
445
445
446
+ impl float: num:: Zero {
447
+ static pure fn zero( ) -> float { 0 . 0 }
448
+ }
449
+
450
+ impl float: num:: One {
451
+ static pure fn one( ) -> float { 1 . 0 }
452
+ }
453
+
446
454
#[ test]
447
455
pub fn test_from_str ( ) {
448
456
assert from_str ( ~"3 ") == Some ( 3. ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,14 @@ impl T: num::Num {
91
91
static pure fn from_int( n: int ) -> T { return n as T ; }
92
92
}
93
93
94
+ impl T : num:: Zero {
95
+ static pure fn zero( ) -> T { 0 }
96
+ }
97
+
98
+ impl T : num:: One {
99
+ static pure fn one( ) -> T { 1 }
100
+ }
101
+
94
102
impl T : iter:: Times {
95
103
#[ inline( always) ]
96
104
#[ doc = "A convenience form for basic iteration. Given a variable `x` \
Original file line number Diff line number Diff line change @@ -22,3 +22,11 @@ pub trait Num {
22
22
pure fn to_int ( & self ) -> int ;
23
23
static pure fn from_int ( n : int ) -> self ;
24
24
}
25
+
26
+ pub trait Zero {
27
+ static pure fn zero( ) -> self ;
28
+ }
29
+
30
+ pub trait One {
31
+ static pure fn one( ) -> self ;
32
+ }
Original file line number Diff line number Diff line change @@ -85,6 +85,14 @@ impl T: num::Num {
85
85
static pure fn from_int( n: int ) -> T { return n as T ; }
86
86
}
87
87
88
+ impl T : num:: Zero {
89
+ static pure fn zero( ) -> T { 0 }
90
+ }
91
+
92
+ impl T : num:: One {
93
+ static pure fn one( ) -> T { 1 }
94
+ }
95
+
88
96
impl T : iter:: Times {
89
97
#[ inline( always) ]
90
98
#[ doc = "A convenience form for basic iteration. Given a variable `x` \
You can’t perform that action at this time.
0 commit comments