Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use isqrt #8

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading