Crates.io | machine-prime |
lib.rs | machine-prime |
version | |
source | src |
created_at | 2023-04-24 18:55:51.305437 |
updated_at | 2024-11-12 17:13:04.601985 |
description | ne plus ultra primality testing for machine-sized integers |
homepage | |
repository | https://github.com/JASory/machine-prime |
max_upload_size | |
id | 847729 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Machine prime is a simple, efficient primality test for 64-bit integers, targeting research applications and casual use.
Two functions are provided with a C-style api to enable calling in other languages. Both can be called in const contexts.
is_prime is optimised for the average case and is intended as a general primality test. is_prime_wc is optimised for the worst case and is intended to be used in functions that the number is already suspected to be prime.It performs absolutely minimal checks, and is permitted to have a handful of known failure points leaving it up to the user to decide if it is necessary to expend the cost to check for them.
This function api will never change. is_prime will always correctly evaluate any 64-bit integer, however is_prime_wc failure points may change.See source code or documentation for a list of these failure points.
Four modes are available for these functions, Default, SSMR and Small and Tiny. Memory use decreases but the complexity increases with each successive mode.
SSMR is the fastest for small values (n< 2^40) but may be slower than Default for larger values (n > 2^40). This is the recommended version to be used, since most applications are going to be smaller primes, and is_prime_wc is nearly twice as fast for (n < 2^40).
Due to some barriers to compiling no-std libraries, the version in crates.io and the repository are slightly different, although using the exact same algorithms. crates.io version is configured for stable compilers, while the repository is configured for nightly compiler, as the intention is to use it to build dynamic libraries.
To use from crates.io, simply include it in your cargo.toml file with the feature "ssmr","small" or "tiny" if you want those versions.
To use as a dynamic library, make sure you are running rustc nightly; git clone
this repository and run make
to compile the Default mode, 'make ssmr' for the SSMR mode, make small
for the Small mode and make tiny
for
the Tiny mode. This will create the library, and make install
will install it to /lib/libprime.so
.
(Make sure you are superuser). Installing the library is recommended but not strictly necessary. Link to it using
-lprime
if you are using gcc.
Alternately, if on Windows, use the provided batch file.
See the "binding" folder in the repository for various language bindings. Several languages including the following are supported.
Due to Machine-primes speed, quite a few applications can be found for it, including in research projects.
is_prime
is_prime_wc is much more useful as it is faster against numbers that are already very likely to be prime
See Performance for some benchmarks and comparison to other efficient primality tests.
Approximate size of binary dynamic library varies with your compiler however the following are reasonable estimates:
Building for embedded systems has not been tested, however there is no known cause for failure.
This software is in public domain, and can be constructed in a reproducible manner with the f-analysis library, and Feitsma/Galway's base-2 pseudoprime table. It is available on crates.io