about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-04-24 20:08:08 +1000
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-04-25 08:20:00 +1000
commit03932f0b84e94f0ef96e4a6de6cb16ab436311e4 (patch)
tree15cdbafa83d1ac03c9d39f7d76d4d82a12cfa683
parent593bdd9be3959f166c303e3da0678cc9598bffc4 (diff)
downloadrust-03932f0b84e94f0ef96e4a6de6cb16ab436311e4.tar.gz
rust-03932f0b84e94f0ef96e4a6de6cb16ab436311e4.zip
Move impls of `Num` out of core::num and clean up imports
-rw-r--r--src/libcore/num/f32.rs25
-rw-r--r--src/libcore/num/f64.rs25
-rw-r--r--src/libcore/num/float.rs24
-rw-r--r--src/libcore/num/int-template.rs10
-rw-r--r--src/libcore/num/num.rs35
-rw-r--r--src/libcore/num/uint-template.rs11
6 files changed, 53 insertions, 77 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index 5d663844e5b..e72356aa3cb 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -10,20 +10,10 @@
 
 //! Operations and constants for `f32`
 
-use num::strconv;
-use num::Signed;
-use num;
-use option::Option;
 use from_str;
-use to_str;
-
-#[cfg(notest)] use cmp::{Eq, Ord};
-#[cfg(stage0,notest)]
-use ops::{Add, Sub, Mul, Div, Modulo, Neg};
-#[cfg(stage1,notest)]
-#[cfg(stage2,notest)]
-#[cfg(stage3,notest)]
-use ops::{Add, Sub, Mul, Quot, Rem, Neg};
+use libc::c_int;
+use num::strconv;
+use prelude::*;
 
 pub use cmath::c_float_targ_consts::*;
 
@@ -233,6 +223,8 @@ pub fn logarithm(n: f32, b: f32) -> f32 {
     return log2(n) / log2(b);
 }
 
+impl Num for f32 {}
+
 #[cfg(notest)]
 impl Eq for f32 {
     #[inline(always)]
@@ -588,6 +580,13 @@ impl num::FromStrRadix for f32 {
 #[cfg(test)]
 mod tests {
     use f32::*;
+    use super::*;
+    use prelude::*;
+
+    #[test]
+    fn test_num() {
+        num::test_num(10f32, 2f32);
+    }
 
     #[test]
     pub fn test_signed() {
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index 48f23fe8ba9..c9867f5e6d4 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -10,20 +10,10 @@
 
 //! Operations and constants for `f64`
 
-use num::strconv;
-use num::Signed;
-use num;
-use option::Option;
-use to_str;
 use from_str;
-
-#[cfg(notest)] use cmp::{Eq, Ord};
-#[cfg(stage0,notest)]
-use ops::{Add, Sub, Mul, Div, Modulo, Neg};
-#[cfg(stage1,notest)]
-#[cfg(stage2,notest)]
-#[cfg(stage3,notest)]
-use ops::{Add, Sub, Mul, Quot, Rem, Neg};
+use libc::c_int;
+use num::strconv;
+use prelude::*;
 
 pub use cmath::c_double_targ_consts::*;
 pub use cmp::{min, max};
@@ -254,6 +244,8 @@ pub fn logarithm(n: f64, b: f64) -> f64 {
     return log2(n) / log2(b);
 }
 
+impl Num for f64 {}
+
 #[cfg(notest)]
 impl Eq for f64 {
     #[inline(always)]
@@ -596,6 +588,13 @@ impl num::FromStrRadix for f64 {
 #[cfg(test)]
 mod tests {
     use f64::*;
+    use super::*;
+    use prelude::*;
+
+    #[test]
+    fn test_num() {
+        num::test_num(10f64, 2f64);
+    }
 
     #[test]
     pub fn test_signed() {
diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs
index 036d295943c..e2f3a4cbcdb 100644
--- a/src/libcore/num/float.rs
+++ b/src/libcore/num/float.rs
@@ -20,21 +20,10 @@
 
 // PORT this must match in width according to architecture
 
-use f64;
-use num::strconv;
-use num::Signed;
-use num;
-use option::Option;
-use to_str;
 use from_str;
-
-#[cfg(notest)] use cmp::{Eq, Ord};
-#[cfg(stage0,notest)]
-use ops::{Add, Sub, Mul, Div, Modulo, Neg};
-#[cfg(stage1,notest)]
-#[cfg(stage2,notest)]
-#[cfg(stage3,notest)]
-use ops::{Add, Sub, Mul, Quot, Rem, Neg};
+use libc::c_int;
+use num::strconv;
+use prelude::*;
 
 pub use f64::{add, sub, mul, quot, rem, lt, le, eq, ne, ge, gt};
 pub use f64::logarithm;
@@ -382,6 +371,8 @@ pub fn tan(x: float) -> float {
     f64::tan(x as f64) as float
 }
 
+impl Num for float {}
+
 #[cfg(notest)]
 impl Eq for float {
     #[inline(always)]
@@ -525,6 +516,11 @@ mod tests {
     use prelude::*;
 
     #[test]
+    fn test_num() {
+        num::test_num(10f, 2f);
+    }
+
+    #[test]
     pub fn test_signed() {
         assert_eq!(infinity.abs(), infinity);
         assert_eq!(1f.abs(), 1f);
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index 426ed8a8b0f..6598efa759e 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -10,12 +10,9 @@
 
 use T = self::inst::T;
 
-use to_str::ToStr;
 use from_str::FromStr;
 use num::{ToStrRadix, FromStrRadix};
 use num::strconv;
-use num::Signed;
-use num;
 use prelude::*;
 
 pub use cmp::{min, max};
@@ -133,6 +130,8 @@ pub fn compl(i: T) -> T {
 #[inline(always)]
 pub fn abs(i: T) -> T { i.abs() }
 
+impl Num for T {}
+
 #[cfg(notest)]
 impl Ord for T {
     #[inline(always)]
@@ -523,6 +522,11 @@ mod tests {
     use prelude::*;
 
     #[test]
+    fn test_num() {
+        num::test_num(10 as T, 2 as T);
+    }
+
+    #[test]
     pub fn test_signed() {
         assert_eq!((1 as T).abs(), 1 as T);
         assert_eq!((0 as T).abs(), 0 as T);
diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs
index 577bb3f0f15..62ed80114d3 100644
--- a/src/libcore/num/num.rs
+++ b/src/libcore/num/num.rs
@@ -33,30 +33,18 @@ pub trait Num: Eq + Zero + One
              + Quot<Self,Self>
              + Rem<Self,Self> {}
 
-impl Num for u8 {}
-impl Num for u16 {}
-impl Num for u32 {}
-impl Num for u64 {}
-impl Num for uint {}
-impl Num for i8 {}
-impl Num for i16 {}
-impl Num for i32 {}
-impl Num for i64 {}
-impl Num for int {}
-impl Num for f32 {}
-impl Num for f64 {}
-impl Num for float {}
-
 pub trait IntConvertible {
     fn to_int(&self) -> int;
     fn from_int(n: int) -> Self;
 }
 
 pub trait Zero {
+    // FIXME (#5527): These should be associated constants
     fn zero() -> Self;
 }
 
 pub trait One {
+    // FIXME (#5527): These should be associated constants
     fn one() -> Self;
 }
 
@@ -230,8 +218,9 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Quot<T,T>+Mul<T,T>>(
     total
 }
 
+/// Helper function for testing numeric operations
 #[cfg(stage0,test)]
-fn test_num<T:Num + NumCast>(ten: T, two: T) {
+pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
     assert_eq!(ten.add(&two),    cast(12));
     assert_eq!(ten.sub(&two),    cast(8));
     assert_eq!(ten.mul(&two),    cast(20));
@@ -247,7 +236,7 @@ fn test_num<T:Num + NumCast>(ten: T, two: T) {
 #[cfg(stage1,test)]
 #[cfg(stage2,test)]
 #[cfg(stage3,test)]
-fn test_num<T:Num + NumCast>(ten: T, two: T) {
+pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
     assert_eq!(ten.add(&two),  cast(12));
     assert_eq!(ten.sub(&two),  cast(8));
     assert_eq!(ten.mul(&two),  cast(20));
@@ -261,20 +250,6 @@ fn test_num<T:Num + NumCast>(ten: T, two: T) {
     assert_eq!(ten.rem(&two),  ten % two);
 }
 
-#[test] fn test_u8_num()    { test_num(10u8,  2u8)  }
-#[test] fn test_u16_num()   { test_num(10u16, 2u16) }
-#[test] fn test_u32_num()   { test_num(10u32, 2u32) }
-#[test] fn test_u64_num()   { test_num(10u64, 2u64) }
-#[test] fn test_uint_num()  { test_num(10u,   2u)   }
-#[test] fn test_i8_num()    { test_num(10i8,  2i8)  }
-#[test] fn test_i16_num()   { test_num(10i16, 2i16) }
-#[test] fn test_i32_num()   { test_num(10i32, 2i32) }
-#[test] fn test_i64_num()   { test_num(10i64, 2i64) }
-#[test] fn test_int_num()   { test_num(10i,   2i)   }
-#[test] fn test_f32_num()   { test_num(10f32, 2f32) }
-#[test] fn test_f64_num()   { test_num(10f64, 2f64) }
-#[test] fn test_float_num() { test_num(10f,   2f)   }
-
 macro_rules! test_cast_20(
     ($_20:expr) => ({
         let _20 = $_20;
diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs
index a0da84a8c53..fc0fe2d3a4d 100644
--- a/src/libcore/num/uint-template.rs
+++ b/src/libcore/num/uint-template.rs
@@ -11,13 +11,9 @@
 use T = self::inst::T;
 use T_SIGNED = self::inst::T_SIGNED;
 
-use to_str::ToStr;
 use from_str::FromStr;
 use num::{ToStrRadix, FromStrRadix};
 use num::strconv;
-use num::Unsigned;
-use num;
-use option::Option;
 use prelude::*;
 
 pub use cmp::{min, max};
@@ -100,6 +96,8 @@ pub fn compl(i: T) -> T {
     max_value ^ i
 }
 
+impl Num for T {}
+
 #[cfg(notest)]
 impl Ord for T {
     #[inline(always)]
@@ -357,6 +355,11 @@ mod tests {
     use prelude::*;
 
     #[test]
+    fn test_num() {
+        num::test_num(10 as T, 2 as T);
+    }
+
+    #[test]
     fn test_gcd() {
         assert_eq!((10 as T).gcd(2), 2 as T);
         assert_eq!((10 as T).gcd(3), 1 as T);