Browse Source

Merge pull request #121 from wrieger93/issue_120

Add a function that returns the sign of a BigInt.
Josh Stone 9 years ago
parent
commit
642787fbd2
1 changed files with 16 additions and 0 deletions
  1. 16 0
      src/bigint.rs

+ 16 - 0
src/bigint.rs

@@ -1779,6 +1779,22 @@ impl BigInt {
         (self.sign, self.data.to_bytes_be())
     }
 
+    /// Returns the sign of the `BigInt` as a `Sign`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use num::bigint::{ToBigInt, Sign};
+    ///
+    /// assert_eq!(ToBigInt::to_bigint(&1234).unwrap().sign(), Sign::Plus);
+    /// assert_eq!(ToBigInt::to_bigint(&-4321).unwrap().sign(), Sign::Minus);
+    /// assert_eq!(ToBigInt::to_bigint(&0).unwrap().sign(), Sign::NoSign);
+    /// ```
+    #[inline]
+    pub fn sign(&self) -> Sign {
+        self.sign
+    }
+
     /// Creates and initializes a `BigInt`.
     ///
     /// # Examples