about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-09-25 15:15:49 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-09-25 15:52:41 -0700
commite85a3d82470e2e45db370b62e4fd54175c4b144d (patch)
tree078c2e710c3a240bc63a5d1bd5192a6cd549652c /src/libcore
parent2d915678926f4b1c64c5916b01f526844f5521b9 (diff)
Demode Num trait and impls
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/f32.rs10
-rw-r--r--src/libcore/f64.rs10
-rw-r--r--src/libcore/float.rs36
-rw-r--r--src/libcore/int-template.rs20
-rw-r--r--src/libcore/num.rs10
-rw-r--r--src/libcore/str.rs2
-rw-r--r--src/libcore/uint-template.rs10
7 files changed, 49 insertions, 49 deletions
diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs
index a8ca15f6afc..f5e4d629726 100644
--- a/src/libcore/f32.rs
+++ b/src/libcore/f32.rs
@@ -158,11 +158,11 @@ pure fn logarithm(n: f32, b: f32) -> f32 {
 }
 
 impl f32: num::Num {
-    pure fn add(&&other: f32)    -> f32 { return self + other; }
-    pure fn sub(&&other: f32)    -> f32 { return self - other; }
-    pure fn mul(&&other: f32)    -> f32 { return self * other; }
-    pure fn div(&&other: f32)    -> f32 { return self / other; }
-    pure fn modulo(&&other: f32) -> f32 { return self % other; }
+    pure fn add(other: &f32)    -> f32 { return self + *other; }
+    pure fn sub(other: &f32)    -> f32 { return self - *other; }
+    pure fn mul(other: &f32)    -> f32 { return self * *other; }
+    pure fn div(other: &f32)    -> f32 { return self / *other; }
+    pure fn modulo(other: &f32) -> f32 { return self % *other; }
     pure fn neg()                -> f32 { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs
index 0be0a059132..56f9cd85db9 100644
--- a/src/libcore/f64.rs
+++ b/src/libcore/f64.rs
@@ -185,11 +185,11 @@ pure fn logarithm(n: f64, b: f64) -> f64 {
 }
 
 impl f64: num::Num {
-    pure fn add(&&other: f64)    -> f64 { return self + other; }
-    pure fn sub(&&other: f64)    -> f64 { return self - other; }
-    pure fn mul(&&other: f64)    -> f64 { return self * other; }
-    pure fn div(&&other: f64)    -> f64 { return self / other; }
-    pure fn modulo(&&other: f64) -> f64 { return self % other; }
+    pure fn add(other: &f64)    -> f64 { return self + *other; }
+    pure fn sub(other: &f64)    -> f64 { return self - *other; }
+    pure fn mul(other: &f64)    -> f64 { return self * *other; }
+    pure fn div(other: &f64)    -> f64 { return self / *other; }
+    pure fn modulo(other: &f64) -> f64 { return self % *other; }
     pure fn neg()                -> f64 { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
diff --git a/src/libcore/float.rs b/src/libcore/float.rs
index 2cd95269aaf..eaa51814056 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -139,7 +139,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
 
     // while we still need digits
     // build stack of digits
-    while ii > 0u && (frac >= epsilon_prime || exact) {
+    while ii > 0 && (frac >= epsilon_prime || exact) {
         // store the next digit
         frac *= 10.0;
         let digit = frac as uint;
@@ -153,25 +153,25 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
 
     let mut acc;
     let mut racc = ~"";
-    let mut carry = if frac * 10.0 as uint >= 5u { 1u } else { 0u };
+    let mut carry = if frac * 10.0 as uint >= 5 { 1 } else { 0 };
 
     // turn digits into string
     // using stack of digits
-    while vec::len(fractionalParts) > 0u {
+    while fractionalParts.is_not_empty() {
         let mut adjusted_digit = carry + vec::pop(fractionalParts);
 
-        if adjusted_digit == 10u {
-            carry = 1u;
-            adjusted_digit %= 10u
+        if adjusted_digit == 10 {
+            carry = 1;
+            adjusted_digit %= 10
         } else {
-            carry = 0u
+            carry = 0;
         };
 
         racc = uint::str(adjusted_digit) + racc;
     }
 
     // pad decimals with trailing zeroes
-    while str::len(racc) < digits && exact {
+    while racc.len() < digits && exact {
         racc += ~"0"
     }
 
@@ -428,11 +428,11 @@ impl float : Ord {
 }
 
 impl float: num::Num {
-    pure fn add(&&other: float)    -> float { return self + other; }
-    pure fn sub(&&other: float)    -> float { return self - other; }
-    pure fn mul(&&other: float)    -> float { return self * other; }
-    pure fn div(&&other: float)    -> float { return self / other; }
-    pure fn modulo(&&other: float) -> float { return self % other; }
+    pure fn add(other: &float)    -> float { return self + *other; }
+    pure fn sub(other: &float)    -> float { return self - *other; }
+    pure fn mul(other: &float)    -> float { return self * *other; }
+    pure fn div(other: &float)    -> float { return self / *other; }
+    pure fn modulo(other: &float) -> float { return self % *other; }
     pure fn neg()                  -> float { return -self;        }
 
     pure fn to_int()         -> int   { return self as int; }
@@ -540,11 +540,11 @@ fn test_traits() {
         let two: U = from_int(2);
         assert (two.to_int() == 2);
 
-        assert (ten.add(two) == from_int(12));
-        assert (ten.sub(two) == from_int(8));
-        assert (ten.mul(two) == from_int(20));
-        assert (ten.div(two) == from_int(5));
-        assert (ten.modulo(two) == from_int(0));
+        assert (ten.add(&two) == from_int(12));
+        assert (ten.sub(&two) == from_int(8));
+        assert (ten.mul(&two) == from_int(20));
+        assert (ten.div(&two) == from_int(5));
+        assert (ten.modulo(&two) == from_int(0));
     }
 
     test(&10.0);
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index e1137e6d269..649400e2360 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -81,11 +81,11 @@ impl T : Eq {
 }
 
 impl T: num::Num {
-    pure fn add(&&other: T)    -> T { return self + other; }
-    pure fn sub(&&other: T)    -> T { return self - other; }
-    pure fn mul(&&other: T)    -> T { return self * other; }
-    pure fn div(&&other: T)    -> T { return self / other; }
-    pure fn modulo(&&other: T) -> T { return self % other; }
+    pure fn add(other: &T)    -> T { return self + *other; }
+    pure fn sub(other: &T)    -> T { return self - *other; }
+    pure fn mul(other: &T)    -> T { return self * *other; }
+    pure fn div(other: &T)    -> T { return self / *other; }
+    pure fn modulo(other: &T) -> T { return self % *other; }
     pure fn neg()              -> T { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
@@ -250,11 +250,11 @@ fn test_interfaces() {
         let two: U = from_int(2);
         assert (two.to_int() == 2);
 
-        assert (ten.add(two) == from_int(12));
-        assert (ten.sub(two) == from_int(8));
-        assert (ten.mul(two) == from_int(20));
-        assert (ten.div(two) == from_int(5));
-        assert (ten.modulo(two) == from_int(0));
+        assert (ten.add(&two) == from_int(12));
+        assert (ten.sub(&two) == from_int(8));
+        assert (ten.mul(&two) == from_int(20));
+        assert (ten.div(&two) == from_int(5));
+        assert (ten.modulo(&two) == from_int(0));
         assert (ten.neg() == from_int(-10));
     }
 
diff --git a/src/libcore/num.rs b/src/libcore/num.rs
index d5872933953..585a72d70ae 100644
--- a/src/libcore/num.rs
+++ b/src/libcore/num.rs
@@ -2,11 +2,11 @@
 
 trait Num {
     // FIXME: Trait composition. (#2616)
-    pure fn add(&&other: self) -> self;
-    pure fn sub(&&other: self) -> self;
-    pure fn mul(&&other: self) -> self;
-    pure fn div(&&other: self) -> self;
-    pure fn modulo(&&other: self) -> self;
+    pure fn add(other: &self) -> self;
+    pure fn sub(other: &self) -> self;
+    pure fn mul(other: &self) -> self;
+    pure fn div(other: &self) -> self;
+    pure fn modulo(other: &self) -> self;
     pure fn neg() -> self;
 
     pure fn to_int() -> int;
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 737cd4d9d50..eaaf11dab5d 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -464,7 +464,7 @@ pure fn byte_slice<T>(s: &str, f: fn(v: &[u8]) -> T) -> T {
 
 /// Convert a string to a vector of characters
 pure fn chars(s: &str) -> ~[char] {
-    let mut buf = ~[], i = 0u;
+    let mut buf = ~[], i = 0;
     let len = len(s);
     while i < len {
         let {ch, next} = char_range_at(s, i);
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index dba28ec06e6..f5d2229513d 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -74,11 +74,11 @@ impl T : Eq {
 }
 
 impl T: num::Num {
-    pure fn add(&&other: T)    -> T { return self + other; }
-    pure fn sub(&&other: T)    -> T { return self - other; }
-    pure fn mul(&&other: T)    -> T { return self * other; }
-    pure fn div(&&other: T)    -> T { return self / other; }
-    pure fn modulo(&&other: T) -> T { return self % other; }
+    pure fn add(other: &T)    -> T { return self + *other; }
+    pure fn sub(other: &T)    -> T { return self - *other; }
+    pure fn mul(other: &T)    -> T { return self * *other; }
+    pure fn div(other: &T)    -> T { return self / *other; }
+    pure fn modulo(other: &T) -> T { return self % *other; }
     pure fn neg()              -> T { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }