mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 10:18:11 +00:00
parent
e24ecea1da
commit
e6fdf0761f
3 changed files with 38 additions and 9 deletions
|
@ -200,7 +200,11 @@ mod tests {
|
|||
|
||||
quickcheck! {
|
||||
fn composites(i: u64, j: u64) -> bool {
|
||||
i < 2 || j < 2 || !is_prime(i*j)
|
||||
// TODO: #1559 factor n > 2^64 - 1
|
||||
match i.checked_mul(j) {
|
||||
Some(n) => i < 2 || j < 2 || !is_prime(n),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
// * For the full copyright and license information, please view the LICENSE file
|
||||
// * that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore (vars) kgcdab gcdac gcdbc
|
||||
|
||||
use std::cmp::min;
|
||||
use std::mem::swap;
|
||||
|
||||
|
@ -93,16 +95,35 @@ mod tests {
|
|||
}
|
||||
|
||||
fn scalar_multiplication(a: u64, b: u64, k: u64) -> bool {
|
||||
gcd(k * a, k * b) == k * gcd(a, b)
|
||||
// TODO: #1559 factor n > 2^64 - 1
|
||||
match (k.checked_mul(a), k.checked_mul(b), k.checked_mul(gcd(a, b))) {
|
||||
(Some(ka), Some(kb), Some(kgcdab)) => gcd(ka, kb) == kgcdab,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
|
||||
fn multiplicative(a: u64, b: u64, c: u64) -> bool {
|
||||
// gcd(ab, c) = gcd(a, c) gcd(b, c) when a and b coprime
|
||||
gcd(a, b) != 1 || gcd(a * b, c) == gcd(a, c) * gcd(b, c)
|
||||
// TODO: #1559 factor n > 2^64 - 1
|
||||
match (a.checked_mul(b), gcd(a, c).checked_mul(gcd(b, c))) {
|
||||
(Some(ab), Some(gcdac_gcdbc)) => {
|
||||
// gcd(ab, c) = gcd(a, c) gcd(b, c) when a and b coprime
|
||||
gcd(a, b) != 1 || gcd(ab, c) == gcdac_gcdbc
|
||||
},
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn linearity(a: u64, b: u64, k: u64) -> bool {
|
||||
gcd(a + k * b, b) == gcd(a, b)
|
||||
// TODO: #1559 factor n > 2^64 - 1
|
||||
match k.checked_mul(b) {
|
||||
Some(kb) => {
|
||||
match a.checked_add(kb) {
|
||||
Some(a_plus_kb) => gcd(a_plus_kb, b) == gcd(a, b),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,13 +63,17 @@ mod tests {
|
|||
|
||||
quickcheck! {
|
||||
fn random_values_u32(n: u32) -> bool {
|
||||
let n = 2 * n + 1;
|
||||
modular_inverse(n).wrapping_mul(n) == 1
|
||||
match 2_u32.checked_mul(n) {
|
||||
Some(n) => modular_inverse(n + 1).wrapping_mul(n + 1) == 1,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn random_values_u64(n: u64) -> bool {
|
||||
let n = 2 * n + 1;
|
||||
modular_inverse(n).wrapping_mul(n) == 1
|
||||
match 2_u64.checked_mul(n) {
|
||||
Some(n) => modular_inverse(n + 1).wrapping_mul(n + 1) == 1,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue