From 1eb3deaca876620e3e19d4ab4848d07df1e7224b Mon Sep 17 00:00:00 2001 From: William Rieger Date: Tue, 6 Oct 2015 00:32:32 -0700 Subject: [PATCH] Add a function that returns the sign of a BigInt. --- src/bigint.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bigint.rs b/src/bigint.rs index 10a96eb..87ed29e 100644 --- a/src/bigint.rs +++ b/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