factor::miller_rabin::is_prime: Fix bug
Montgomery only works for odd n, so attempting to construct an instance
for an even number results in a panic!
The most obvious solution is to special-case even numbers.
@@ -84,11 +84,15 @@ pub(crate) fn test<A: Arithmetic>(m: A) -> Result {
Prime
}
-// Used by build.rs' tests
+// Used by build.rs' tests and debug assertions
#[allow(dead_code)]
pub(crate) fn is_prime(n: u64) -> bool {
+ if n % 2 == 0 {
+ n == 2
+ } else {
test::<Montgomery>(Montgomery::new(n)).is_prime()
}
+}
#[cfg(test)]
mod tests {
