commit
c694115f92
|
@ -446,7 +446,7 @@ impl Integer for BigUint {
|
||||||
shift += 1;
|
shift += 1;
|
||||||
}
|
}
|
||||||
assert!(shift < BigDigit::bits);
|
assert!(shift < BigDigit::bits);
|
||||||
let (d, m) = div_mod_floor_inner(self << shift, other << shift);
|
let (d, m) = div_mod_floor_inner(*self << shift, *other << shift);
|
||||||
return (d, m >> shift);
|
return (d, m >> shift);
|
||||||
|
|
||||||
|
|
||||||
|
@ -990,9 +990,9 @@ impl Add<BigInt, BigInt> for BigInt {
|
||||||
(NoSign, _) => other.clone(),
|
(NoSign, _) => other.clone(),
|
||||||
(_, NoSign) => self.clone(),
|
(_, NoSign) => self.clone(),
|
||||||
(Plus, Plus) => BigInt::from_biguint(Plus, self.data + other.data),
|
(Plus, Plus) => BigInt::from_biguint(Plus, self.data + other.data),
|
||||||
(Plus, Minus) => self - (-*other),
|
(Plus, Minus) => *self - (-*other),
|
||||||
(Minus, Plus) => other - (-*self),
|
(Minus, Plus) => *other - (-*self),
|
||||||
(Minus, Minus) => -((-self) + (-*other))
|
(Minus, Minus) => -((-*self) + (-*other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1001,16 +1001,16 @@ impl Sub<BigInt, BigInt> for BigInt {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, other: &BigInt) -> BigInt {
|
fn sub(&self, other: &BigInt) -> BigInt {
|
||||||
match (self.sign, other.sign) {
|
match (self.sign, other.sign) {
|
||||||
(NoSign, _) => -other,
|
(NoSign, _) => -*other,
|
||||||
(_, NoSign) => self.clone(),
|
(_, NoSign) => self.clone(),
|
||||||
(Plus, Plus) => match self.data.cmp(&other.data) {
|
(Plus, Plus) => match self.data.cmp(&other.data) {
|
||||||
Less => BigInt::from_biguint(Minus, other.data - self.data),
|
Less => BigInt::from_biguint(Minus, other.data - self.data),
|
||||||
Greater => BigInt::from_biguint(Plus, self.data - other.data),
|
Greater => BigInt::from_biguint(Plus, self.data - other.data),
|
||||||
Equal => Zero::zero()
|
Equal => Zero::zero()
|
||||||
},
|
},
|
||||||
(Plus, Minus) => self + (-*other),
|
(Plus, Minus) => *self + (-*other),
|
||||||
(Minus, Plus) => -((-self) + *other),
|
(Minus, Plus) => -((-*self) + *other),
|
||||||
(Minus, Minus) => (-other) - (-*self)
|
(Minus, Minus) => (-*other) - (-*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1129,7 @@ impl Integer for BigInt {
|
||||||
(Minus, Plus) => if m.is_zero() {
|
(Minus, Plus) => if m.is_zero() {
|
||||||
(-d, Zero::zero())
|
(-d, Zero::zero())
|
||||||
} else {
|
} else {
|
||||||
(-d - One::one(), other - m)
|
(-d - One::one(), *other - m)
|
||||||
},
|
},
|
||||||
(Minus, Minus) => (d, -m)
|
(Minus, Minus) => (d, -m)
|
||||||
}
|
}
|
||||||
|
@ -2562,7 +2562,7 @@ mod bigint_tests {
|
||||||
assert_eq!(m.sign, b.sign);
|
assert_eq!(m.sign, b.sign);
|
||||||
}
|
}
|
||||||
assert!(m.abs() <= b.abs());
|
assert!(m.abs() <= b.abs());
|
||||||
assert!(*a == b * d + m);
|
assert!(*a == (*b) * d + m);
|
||||||
assert!(d == *ans_d);
|
assert!(d == *ans_d);
|
||||||
assert!(m == *ans_m);
|
assert!(m == *ans_m);
|
||||||
}
|
}
|
||||||
|
@ -2575,8 +2575,8 @@ mod bigint_tests {
|
||||||
check_sub(&a.neg(), &b.neg(), d, m);
|
check_sub(&a.neg(), &b.neg(), d, m);
|
||||||
} else {
|
} else {
|
||||||
check_sub(a, b, d, m);
|
check_sub(a, b, d, m);
|
||||||
check_sub(a, &b.neg(), &(d.neg() - One::one()), &(m - *b));
|
check_sub(a, &b.neg(), &(d.neg() - One::one()), &(*m - *b));
|
||||||
check_sub(&a.neg(), b, &(d.neg() - One::one()), &(b - *m));
|
check_sub(&a.neg(), b, &(d.neg() - One::one()), &(*b - *m));
|
||||||
check_sub(&a.neg(), &b.neg(), d, &m.neg());
|
check_sub(&a.neg(), &b.neg(), d, &m.neg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2613,7 +2613,7 @@ mod bigint_tests {
|
||||||
assert_eq!(r.sign, a.sign);
|
assert_eq!(r.sign, a.sign);
|
||||||
}
|
}
|
||||||
assert!(r.abs() <= b.abs());
|
assert!(r.abs() <= b.abs());
|
||||||
assert!(*a == b * q + r);
|
assert!(*a == (*b) * q + r);
|
||||||
assert!(q == *ans_q);
|
assert!(q == *ans_q);
|
||||||
assert!(r == *ans_r);
|
assert!(r == *ans_r);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ macro_rules! impl_integer_for_int {
|
||||||
|
|
||||||
/// Returns `true` if the number is divisible by `2`
|
/// Returns `true` if the number is divisible by `2`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_even(&self) -> bool { self & 1 == 0 }
|
fn is_even(&self) -> bool { (*self) & 1 == 0 }
|
||||||
|
|
||||||
/// Returns `true` if the number is not divisible by `2`
|
/// Returns `true` if the number is not divisible by `2`
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -418,11 +418,11 @@ macro_rules! impl_integer_for_uint {
|
||||||
|
|
||||||
/// Returns `true` if the number is divisible by `2`.
|
/// Returns `true` if the number is divisible by `2`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_even(&self) -> bool { self & 1 == 0 }
|
fn is_even(&self) -> bool { (*self) & 1 == 0 }
|
||||||
|
|
||||||
/// Returns `true` if the number is not divisible by `2`.
|
/// Returns `true` if the number is not divisible by `2`.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_odd(&self) -> bool { !self.is_even() }
|
fn is_odd(&self) -> bool { !(*self).is_even() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue