mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
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.
This commit is contained in:
parent
d2b43f49f9
commit
308290325a
1 changed files with 6 additions and 2 deletions
|
@ -101,10 +101,14 @@ pub(crate) fn test<A: Arithmetic + Basis>(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 {
|
||||
test::<Montgomery<u64>>(Montgomery::new(n)).is_prime()
|
||||
if n % 2 == 0 {
|
||||
n == 2
|
||||
} else {
|
||||
test::<Montgomery<u64>>(Montgomery::new(n)).is_prime()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue