smcprime 0.1.0

Ultra-fast primality testing with Montgomery arithmetic (32-bit and 64-bit)
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented1 out of 10 items with examples
  • Size
  • Source code size: 12.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.39 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • scalecode-solutions/smcPrime
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • scalecode-solutions

smcprime

Ultra-fast primality testing with Montgomery arithmetic (32-bit and 64-bit).

Crates.io Documentation License: MIT

Features

  • Fast: Montgomery arithmetic for 64-bit, native 64-bit math for 32-bit
  • Deterministic: No probabilistic results - always correct
  • no_std compatible: Works in embedded environments
  • Zero dependencies

Usage

use smcprime::{is_prime, is_prime32, is_prime64, next_prime, prev_prime};

// Basic primality testing
assert!(is_prime(17));
assert!(!is_prime(18));

// Find next/previous primes
assert_eq!(next_prime(100), 101);
assert_eq!(prev_prime(100), 97);

// Explicit 32-bit or 64-bit
assert!(is_prime32(104729));
assert!(is_prime64(1000000007));

API

Primality Testing

  • is_prime(n: u64) -> bool - Test if n is prime (64-bit)
  • is_prime32(n: u32) -> bool - Test if n is prime (32-bit)
  • is_prime64(n: u64) -> bool - Test if n is prime (64-bit)

Prime Navigation

  • next_prime(n: u64) -> u64 - Find smallest prime >= n
  • prev_prime(n: u64) -> u64 - Find largest prime <= n
  • next_prime32(n: u32) -> u32 - 32-bit version
  • prev_prime32(n: u32) -> u32 - 32-bit version
  • next_prime64(n: u64) -> u64 - 64-bit version
  • prev_prime64(n: u64) -> u64 - 64-bit version

Performance

  • 32-bit: Uses witnesses {2, 7, 61} - only 3 Miller-Rabin rounds
  • 64-bit: Montgomery arithmetic avoids expensive modular division
  • Benchmarks show ~3x faster than naive implementations

Algorithm

  • Miller-Rabin with deterministic witness sets
  • Montgomery multiplication (no modular division)
  • Hensel lifting for modular inverses
  • Optimal witness selection from machine-prime research

License

MIT License - Copyright 2025 ScaleCode Solutions