Add a function that returns the sign of a BigInt.

This commit is contained in:
William Rieger 2015-10-06 00:32:32 -07:00
parent fde6c479a6
commit 1eb3deaca8
1 changed files with 16 additions and 0 deletions

View File

@ -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