- /// Return the smaller of the two numbers
- pub fn min(self, other: Self) -> Self {
- debug_assert!(self.test_invariant() && other.test_invariant());
- if self.data.len() < other.data.len() {
- self
- } else if self.data.len() > other.data.len() {
- other
- } else {
- // compare back-to-front, i.e., most significant digit first
- let mut idx = self.data.len()-1;
- while idx > 0 {
- if self.data[idx] < other.data[idx] {
- return self;
- } else if self.data[idx] > other.data[idx] {
- return other;
- }
- else {
- idx = idx-1;
- }
- }
- // the two are equal
- return self;
- }
- }
-
- /// Returns a view on the raw digits representing the number.
- ///
- /// ```
- /// use solutions::bigint::BigInt;
- /// let b = BigInt::new(13);
- /// let d = b.data();
- /// assert_eq!(d, [13]);
- /// ```
- pub fn data(&self) -> &[u64] {
- &self.data[..]
- }
-