Skip to content

Commit

Permalink
use isqrt
Browse files Browse the repository at this point in the history
finally
  • Loading branch information
ognevny committed Jan 7, 2025
1 parent 186ffe4 commit c7104ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
[package]
name = "ognlib"
version = "0.7.1"
version = "0.8.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Some code that is written to practice Rust"
authors = ["Maksim Bondarenkov"]
repository = "https://github.com/ognevnydemon/ognlib"
readme = "README.md"
rust-version = "1.81.0"
rust-version = "1.84.0"

[dependencies]
cfg-if = "1.0"
fastrand = { version = "2.2", default-features = false }
# FIXME: use std isqrt after rust 1.84.0 release
integer-sqrt = "0.1"
num-bigint = { version = "0.4", default-features = false }
rayon = { version = "1.10", optional = true }
regex = { version = "1.11", default-features = false }
Expand Down
9 changes: 2 additions & 7 deletions src/algorithm/prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#[cfg(feature = "std")] use rayon::prelude::*;

use {
crate::num::power::modpow, fastrand::Rng, integer_sqrt::IntegerSquareRoot as _,
num_bigint::BigUint, thiserror::Error,
};
use {crate::num::power::modpow, fastrand::Rng, num_bigint::BigUint, thiserror::Error};

/// If number is less than 2, we can't say that number is either prime or composite.
#[non_exhaustive]
Expand Down Expand Up @@ -187,9 +184,7 @@ pub fn sqrtest(num: usize) -> Result<PrimeStatus, PrimeStatusError> {
if num < 2 {
Err(PrimeStatusError)
} else {
// FIXME: https://github.com/rust-lang/rust/issues/116226
// let sqrt_res = num.isqrt() + 1;
let sqrt_res = num.integer_sqrt() + 1;
let sqrt_res = num.isqrt() + 1;
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
let cond = (3..=sqrt_res).into_par_iter().find_any(|&i| num % i == 0).is_some();
Expand Down

0 comments on commit c7104ef

Please sign in to comment.