Lines Matching full:sign
17 use self::Sign::{Minus, NoSign, Plus};
39 /// A Sign is a `BigInt`'s composing element.
41 pub enum Sign { enum
47 impl Neg for Sign { implementation
48 type Output = Sign;
50 /// Negate Sign value.
52 fn neg(self) -> Sign { in neg() argument
63 sign: Sign, field
73 sign: self.sign, in clone()
80 self.sign = other.sign; in clone_from()
88 debug_assert!((self.sign != NoSign) ^ self.data.is_zero()); in hash()
89 self.sign.hash(state); in hash()
90 if self.sign != NoSign { in hash()
99 debug_assert!((self.sign != NoSign) ^ self.data.is_zero()); in eq()
100 debug_assert!((other.sign != NoSign) ^ other.data.is_zero()); in eq()
101 self.sign == other.sign && (self.sign == NoSign || self.data == other.data) in eq()
117 debug_assert!((self.sign != NoSign) ^ self.data.is_zero()); in cmp()
118 debug_assert!((other.sign != NoSign) ^ other.data.is_zero()); in cmp()
119 let scmp = self.sign.cmp(&other.sign); in cmp()
124 match self.sign { in cmp()
185 match self.sign { in not()
188 self.sign = Minus; in not()
192 self.sign = if self.data.is_zero() { NoSign } else { Plus }; in not()
203 match self.sign { in not()
215 sign: NoSign, in zero()
223 self.sign = NoSign; in set_zero()
228 self.sign == NoSign in is_zero()
236 sign: Plus, in one()
244 self.sign = Plus; in set_one()
249 self.sign == Plus && self.data.is_one() in is_one()
256 match self.sign { in abs()
273 match self.sign { in signum()
282 self.sign == Plus in is_positive()
287 self.sign == Minus in is_negative()
340 self.sign = -self.sign; in neg()
357 // r.sign == self.sign in div_rem()
359 let d = BigInt::from_biguint(self.sign, d_ui); in div_rem()
360 let r = BigInt::from_biguint(self.sign, r_ui); in div_rem()
372 match (self.sign, other.sign) { in div_floor()
387 // m.sign == other.sign in mod_floor()
389 let m = BigInt::from_biguint(other.sign, m_ui); in mod_floor()
390 match (self.sign, other.sign) { in mod_floor()
404 // m.sign == other.sign in div_mod_floor()
407 let m = BigInt::from_biguint(other.sign, m_ui); in div_mod_floor()
408 match (self.sign, other.sign) { in div_mod_floor()
425 match (self.sign, other.sign) { in div_ceil()
521 BigInt::from_biguint(self.sign, self.data.nth_root(n)) in nth_root()
527 BigInt::from_biguint(self.sign, self.data.sqrt()) in sqrt()
531 BigInt::from_biguint(self.sign, self.data.cbrt()) in cbrt()
548 self.sign = NoSign; in normalize()
574 pub fn new(sign: Sign, digits: Vec<u32>) -> BigInt { in new() argument
575 BigInt::from_biguint(sign, BigUint::new(digits)) in new()
582 pub fn from_biguint(mut sign: Sign, mut data: BigUint) -> BigInt { in from_biguint() argument
583 if sign == NoSign { in from_biguint()
586 sign = NoSign; in from_biguint()
589 BigInt { sign, data } in from_biguint()
596 pub fn from_slice(sign: Sign, slice: &[u32]) -> BigInt { in from_slice() argument
597 BigInt::from_biguint(sign, BigUint::from_slice(slice)) in from_slice()
604 pub fn assign_from_slice(&mut self, sign: Sign, slice: &[u32]) { in assign_from_slice() argument
605 if sign == NoSign { in assign_from_slice()
609 self.sign = if self.data.is_zero() { NoSign } else { sign }; in assign_from_slice()
620 /// use num_bigint::{BigInt, Sign};
622 /// assert_eq!(BigInt::from_bytes_be(Sign::Plus, b"A"),
624 /// assert_eq!(BigInt::from_bytes_be(Sign::Plus, b"AA"),
626 /// assert_eq!(BigInt::from_bytes_be(Sign::Plus, b"AB"),
628 /// assert_eq!(BigInt::from_bytes_be(Sign::Plus, b"Hello world!"),
632 pub fn from_bytes_be(sign: Sign, bytes: &[u8]) -> BigInt { in from_bytes_be() argument
633 BigInt::from_biguint(sign, BigUint::from_bytes_be(bytes)) in from_bytes_be()
640 pub fn from_bytes_le(sign: Sign, bytes: &[u8]) -> BigInt { in from_bytes_le() argument
641 BigInt::from_biguint(sign, BigUint::from_bytes_le(bytes)) in from_bytes_le()
688 /// use num_bigint::{BigInt, Sign};
691 /// let a = BigInt::from_radix_be(Sign::Minus, &inbase190, 190).unwrap();
692 /// assert_eq!(a.to_radix_be(190), (Sign:: Minus, inbase190));
694 pub fn from_radix_be(sign: Sign, buf: &[u8], radix: u32) -> Option<BigInt> { in from_radix_be() argument
696 Some(BigInt::from_biguint(sign, u)) in from_radix_be()
709 /// use num_bigint::{BigInt, Sign};
712 /// let a = BigInt::from_radix_be(Sign::Minus, &inbase190, 190).unwrap();
713 /// assert_eq!(a.to_radix_be(190), (Sign::Minus, inbase190));
715 pub fn from_radix_le(sign: Sign, buf: &[u8], radix: u32) -> Option<BigInt> { in from_radix_le() argument
717 Some(BigInt::from_biguint(sign, u)) in from_radix_le()
720 /// Returns the sign and the byte representation of the `BigInt` in big-endian byte order.
725 /// use num_bigint::{ToBigInt, Sign};
728 /// assert_eq!(i.to_bytes_be(), (Sign::Minus, vec![4, 101]));
731 pub fn to_bytes_be(&self) -> (Sign, Vec<u8>) { in to_bytes_be() argument
732 (self.sign, self.data.to_bytes_be()) in to_bytes_be()
735 /// Returns the sign and the byte representation of the `BigInt` in little-endian byte order.
740 /// use num_bigint::{ToBigInt, Sign};
743 /// assert_eq!(i.to_bytes_le(), (Sign::Minus, vec![101, 4]));
746 pub fn to_bytes_le(&self) -> (Sign, Vec<u8>) { in to_bytes_le() argument
747 (self.sign, self.data.to_bytes_le()) in to_bytes_le()
750 /// Returns the sign and the `u32` digits representation of the `BigInt` ordered least
756 /// use num_bigint::{BigInt, Sign};
758 /// assert_eq!(BigInt::from(-1125).to_u32_digits(), (Sign::Minus, vec![1125]));
759 /// assert_eq!(BigInt::from(4294967295u32).to_u32_digits(), (Sign::Plus, vec![4294967295]));
760 /// assert_eq!(BigInt::from(4294967296u64).to_u32_digits(), (Sign::Plus, vec![0, 1]));
761 …/// assert_eq!(BigInt::from(-112500000000i64).to_u32_digits(), (Sign::Minus, vec![830850304, 26]));
762 … /// assert_eq!(BigInt::from(112500000000i64).to_u32_digits(), (Sign::Plus, vec![830850304, 26]));
765 pub fn to_u32_digits(&self) -> (Sign, Vec<u32>) { in to_u32_digits() argument
766 (self.sign, self.data.to_u32_digits()) in to_u32_digits()
769 /// Returns the sign and the `u64` digits representation of the `BigInt` ordered least
775 /// use num_bigint::{BigInt, Sign};
777 /// assert_eq!(BigInt::from(-1125).to_u64_digits(), (Sign::Minus, vec![1125]));
778 /// assert_eq!(BigInt::from(4294967295u32).to_u64_digits(), (Sign::Plus, vec![4294967295]));
779 /// assert_eq!(BigInt::from(4294967296u64).to_u64_digits(), (Sign::Plus, vec![4294967296]));
780 … /// assert_eq!(BigInt::from(-112500000000i64).to_u64_digits(), (Sign::Minus, vec![112500000000]));
781 /// assert_eq!(BigInt::from(112500000000i64).to_u64_digits(), (Sign::Plus, vec![112500000000]));
782 /// assert_eq!(BigInt::from(1u128 << 64).to_u64_digits(), (Sign::Plus, vec![0, 1]));
785 pub fn to_u64_digits(&self) -> (Sign, Vec<u64>) { in to_u64_digits() argument
786 (self.sign, self.data.to_u64_digits()) in to_u64_digits()
889 /// use num_bigint::{BigInt, Sign};
892 /// (Sign::Minus, vec![2, 94, 27]));
896 pub fn to_radix_be(&self, radix: u32) -> (Sign, Vec<u8>) { in to_radix_be() argument
897 (self.sign, self.data.to_radix_be(radix)) in to_radix_be()
908 /// use num_bigint::{BigInt, Sign};
911 /// (Sign::Minus, vec![27, 94, 2]));
915 pub fn to_radix_le(&self, radix: u32) -> (Sign, Vec<u8>) { in to_radix_le() argument
916 (self.sign, self.data.to_radix_le(radix)) in to_radix_le()
919 /// Returns the sign of the `BigInt` as a `Sign`.
924 /// use num_bigint::{BigInt, Sign};
927 /// assert_eq!(BigInt::from(1234).sign(), Sign::Plus);
928 /// assert_eq!(BigInt::from(-4321).sign(), Sign::Minus);
929 /// assert_eq!(BigInt::zero().sign(), Sign::NoSign);
932 pub fn sign(&self) -> Sign { in sign() method
933 self.sign in sign()
953 /// Convert this `BigInt` into its `Sign` and `BigUint` magnitude,
959 /// use num_bigint::{BigInt, BigUint, Sign};
962 /// assert_eq!(BigInt::from(1234).into_parts(), (Sign::Plus, BigUint::from(1234u32)));
963 /// assert_eq!(BigInt::from(-4321).into_parts(), (Sign::Minus, BigUint::from(4321u32)));
964 /// assert_eq!(BigInt::zero().into_parts(), (Sign::NoSign, BigUint::zero()));
967 pub fn into_parts(self) -> (Sign, BigUint) { in into_parts() argument
968 (self.sign, self.data) in into_parts()
972 /// not including the sign.
981 match self.sign { in to_biguint()
1083 match self.sign { in set_bit()
1084 Sign::Plus => self.data.set_bit(bit, value), in set_bit()
1085 Sign::Minus => bits::set_negative_bit(self, bit, value), in set_bit()
1086 Sign::NoSign => { in set_bit()
1089 self.sign = Sign::Plus; in set_bit()
1102 fn check(inp_s: Sign, inp_n: usize, ans_s: Sign, ans_n: usize) { in test_from_biguint() argument
1105 sign: ans_s, in test_from_biguint()
1118 fn check(inp_s: Sign, inp_n: u32, ans_s: Sign, ans_n: u32) { in test_from_slice() argument
1121 sign: ans_s, in test_from_slice()
1134 fn check(inp_s: Sign, inp_n: u32, ans_s: Sign, ans_n: u32) { in test_assign_from_slice() argument
1138 sign: ans_s, in test_assign_from_slice()