about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJames Miller <bladeon@gmail.com>2013-04-24 18:34:00 +1200
committerJames Miller <bladeon@gmail.com>2013-04-24 18:34:00 +1200
commit507c200da17cde760f359da4be1fa13e723cab19 (patch)
treebeb7e3acfd9cf4be23eb214394f57eb2499178b3 /src/libstd
parent286e571a634e9677fe897ff8fb46a7e33487b4c5 (diff)
parentc8ac057545f7b2edf1e488aa4562138a6ed7a096 (diff)
downloadrust-507c200da17cde760f359da4be1fa13e723cab19.tar.gz
rust-507c200da17cde760f359da4be1fa13e723cab19.zip
Merge branch 'incoming' of git://github.com/mozilla/rust into unwind-fix
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/num/bigint.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs
index ee9749af532..5f0fd76640a 100644
--- a/src/libstd/num/bigint.rs
+++ b/src/libstd/num/bigint.rs
@@ -154,6 +154,8 @@ impl One for BigUint {
     pub fn one() -> BigUint { BigUint::new(~[1]) }
 }
 
+impl Unsigned for BigUint {}
+
 impl Add<BigUint, BigUint> for BigUint {
     fn add(&self, other: &BigUint) -> BigUint {
         let new_len = uint::max(self.data.len(), other.data.len());
@@ -469,11 +471,8 @@ pub impl BigUint {
     }
 
     fn is_zero(&self) -> bool { self.data.is_empty() }
+
     fn is_not_zero(&self) -> bool { !self.data.is_empty() }
-    fn is_positive(&self) -> bool { self.is_not_zero() }
-    fn is_negative(&self) -> bool { false }
-    fn is_nonpositive(&self) -> bool { self.is_zero() }
-    fn is_nonnegative(&self) -> bool { true }
 
     fn to_uint(&self) -> uint {
         match self.data.len() {
@@ -693,6 +692,27 @@ impl One for BigInt {
     }
 }
 
+impl Signed for BigInt {
+    fn abs(&self) -> BigInt {
+        match self.sign {
+            Plus | Zero => copy *self,
+            Minus => BigInt::from_biguint(Plus, copy self.data)
+        }
+    }
+
+    fn signum(&self) -> BigInt {
+        match self.sign {
+            Plus  => BigInt::from_biguint(Plus, One::one()),
+            Minus => BigInt::from_biguint(Minus, One::one()),
+            Zero  => Zero::zero(),
+        }
+    }
+
+    fn is_positive(&self) -> bool { self.sign == Plus }
+
+    fn is_negative(&self) -> bool { self.sign == Minus }
+}
+
 impl Add<BigInt, BigInt> for BigInt {
     fn add(&self, other: &BigInt) -> BigInt {
         match (self.sign, other.sign) {
@@ -888,11 +908,8 @@ pub impl BigInt {
     }
 
     fn is_zero(&self) -> bool { self.sign == Zero }
+
     fn is_not_zero(&self) -> bool { self.sign != Zero }
-    fn is_positive(&self) -> bool { self.sign == Plus }
-    fn is_negative(&self) -> bool { self.sign == Minus }
-    fn is_nonpositive(&self) -> bool { self.sign != Plus }
-    fn is_nonnegative(&self) -> bool { self.sign != Minus }
 
     fn to_uint(&self) -> uint {
         match self.sign {