diff --git a/.gitignore b/.gitignore index e2e6283..7d6ed6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -target -.vscode -.idea -*.lock +/target +/.vscode +/.idea +/*.lock +/.zed # internal script -clean +/clean diff --git a/Cargo.toml b/Cargo.toml index 6592ccd..ea95e89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ rust-version = "1.81.0" [dependencies] cfg-if = "1" fastrand = { version = "2", default-features = false } +integer-sqrt = "0" num-bigint = { version = "0", default-features = false } rayon = { version = "1", optional = true } regex = { version = "1", default-features = false } diff --git a/src/algorithm/prime.rs b/src/algorithm/prime.rs index 050ad21..126e1be 100644 --- a/src/algorithm/prime.rs +++ b/src/algorithm/prime.rs @@ -4,7 +4,10 @@ #[cfg(feature = "std")] use rayon::prelude::*; -use {crate::num::power::modpow, fastrand::Rng, num_bigint::BigUint, snafu::Snafu}; +use { + crate::num::power::modpow, fastrand::Rng, integer_sqrt::IntegerSquareRoot, num_bigint::BigUint, + snafu::Snafu, +}; /// If number is less than 2, we can't say that number is either prime or composite. #[non_exhaustive] @@ -142,8 +145,8 @@ pub fn sqrtest(num: usize) -> Result { Err(PrimeStatusError) } else { // FIXME: https://github.com/rust-lang/rust/issues/116226 - // let sqrt_res = num.isqrt().unsigned_abs() - let sqrt_res = (num as f64).sqrt().ceil() as usize; + // let sqrt_res = num.isqrt() + 1; + let sqrt_res = num.integer_sqrt() + 1; if (3..=sqrt_res).into_par_iter().find_any(|&i| num % i == 0).is_some() { Ok(PrimeStatus::Composite) } else {