Crates.io | prime-checker |
lib.rs | prime-checker |
version | 0.2.21 |
source | src |
created_at | 2023-05-05 22:23:17.516776 |
updated_at | 2023-07-28 18:18:08.807078 |
description | Rust library crate to hold sample functions to check the prime-ness of a given unsigned, 64-bit integer. |
homepage | |
repository | https://github.com/Arkiralor/PrimeChecker/ |
max_upload_size | |
id | 858056 |
size | 37,524 |
A sample rust package to check the prime-ness of a given unsigned, 64-bit integer.
Do note that wherever we use square brackets in this section, we are using the mathematical expression for an inclusive boundary.
Any whole number (or natural number, depending on who you ask) num
, can have one of the following three prime-ness values:
[1, num]
.[1, [z (- Z], num]
where z
can be any natural number exclusively between 1
and num
.1
, 2
) but the length of the list is the greatest for the set [num-z
, num
] i.e, it exclusively has the highest number of factors for any natural number less than it.The library here holds functions that help determine and select unsigned, 64-bit integers depending on these three criteria.
The autogenerated Rust documentation can be viewed at the Docs.RS website.
It may take a few hours for docs to propagate after a new version has been uploaded, you can check the build queue here.
Here we will go over the very basics of the functions defined in the lib.rs
file.
is_hcn()
Checks if the given number is a highly-composite (anti-prime) number.
Arguments: num: u64
Returns: bool | default: false
, Vec<u64>
where the vector
is list of the given number, num
's factors.
Usage:
use prime_checker;
fn main(){
let num: u64 = z; // z belongs to the set of natural numbers and is only used as a placeholder by us in this README.
let check: bool;
let factors: Vec<u64>;
(check, factors) = prime_checker::is_hcn(num: num);
if check == true{
println!("{} is a highly composite number.", num);
}
else {
println!("{} is not a highly composite number; here are its factors: {:?}", num, factors);
}
}
is_prime()
Checks if the given number is a prime number.
Arguments: num: u64
Returns: bool | default: false
, Vec<u64>
where the vector
is list of the given number, num
's factors.
Usage:
use prime_checker;
fn main(){
let num: u64 = z; // z belongs to the set of natural numbers and is only used as a placeholder by us in this README.
let check: bool;
let factors: Vec<u64>;
(check, factors) = prime_checker::is_prime(num: num);
if check == true{
println!("{} is a prime number.", num);
}
else {
println!("{} is not a prime number; here are its factors: {:?}", num, factors);
}
}
description()
Returns a brief description of this library crate and if show
is set to true
, prints the same to the console.
Arguments: show: bool
Returns: String
Usage:
use prime_checker;
fn main(){
let desc_str = prime_checker::description(true);
}
get_primes()
Finds all prime numbers which are less than or equal to the given number.
Arguments: num: u64
Returns: Vec<u64>
where the vector
is list all prime numbers which are less than or equal to the given number, num
.
Usage:
use prime_checker;
fn main(){
let num: u64 = z; // z belongs to the set of natural numbers and is only used as a placeholder by us in this README.
let prime_numbers: Vec<u64>;
prime_numbers = prime_checker::get_primes(num: num);
println!("The prime numbers till {} are:\t{:?}", num, prime_numbers);
}
get_hcn()
Finds all anti-prime numbers which are less than or equal to the given number.
Arguments: num: u64
Returns: Vec<u64>
which is the list of all highly-composite numbers less than or equal to the given number, num
.
Usage:
use prime_checker;
fn main(){
let num: u64 = z; // z belongs to the set of natural numbers and is only used as a placeholder by us in this README.
let anti_prime_numbers: Vec<u64>;
anti_prime_numbers = prime_checker::get_hcn(num: num);
println!("The anti-prime numbers till {} are:\t{:?}", num, anti_prime_numbers);
}
WARNING: HIGHLY Unoptimized and Computationally Expensive1.
If you want to contribute to this library, kindly follow the steps described below.
Misc_001
, then the branch name will be misc-001
.cargo test --verbose
to make sure everything works and is validated.
master
branch of the main repository and run all tests again.
Pull Request
to the master
branch of the main repository with the required details and a sensible PR
title.Make sure the pre-requisites are satified before proceeding further.
DO NOT use the nightly
build of Rust for this. We cannot vouch for any behaviour due to differences between the stable
and nightly
builds.
chmod +x scripts/*
to give all scripts in the scripts
directory permission to execute.
sh scripts/build.sh both
to build both, the release
and debug
versions of the library.
cargo test --verbose
to make sure everything was copied correctly and is working as intended.
(ɔ) 2023 Arkiralor (Prithoo Medhi)
Takes approximately 64 seconds to check 6'160 values beyond the last element of prime_checker::libs::constants::KNOWN_ANTIPRIMES
. ↩