c_prime/
lib.rs

1//! Convenience wrapper for machine-prime. Implements primality testing for all primitive types, including floats. 
2//! Provides iterators and const functions, and modeling of prime sets. 
3//! Primes here are defined as integers that can only be composed of themselves and a unit of the integers {1,-1}.
4//! Therefore numbers with no factor P are primes as well as -P.
5//! ```
6//!   use c_prime::{P,Primality,prime_array,prime_inv_array};
7//!   
8//!   // The set of P contains 17
9//!   assert_eq!(P.contains(17),true);
10//!
11//!   // Go to 2^128-1000 and count the primes from there up to 2^128
12//!   assert_eq!(P.jump_to(u128::MAX-999).count(),9);
13//!  // Count the number of primes under 100
14//!   assert_eq!(P.take_while(|x| *x < 100).count(),25);
15//!
16//!  // Set intersection of the primes and some collection
17//!   assert_eq!(P.intersection([2,4,5,6,7]),[2,5,7]);
18//! 
19//!  // The first 25 primes greater than 100
20//! const ODD_PRIMES : [u128;25] = prime_array(100);
21//! // The multiplicative inverses of these primes
22//! const PRIME_INV : [u128;25] = prime_inv_array(100);
23//! // P*P^-1 = 1
24//! for (p,inv) in ODD_PRIMES.iter().zip(PRIME_INV.iter()){
25//!       assert_eq!(p.wrapping_mul(*inv),1)
26//!  }
27//!   // Of course floats can also be primes so long as they can accurately store them
28//!   // Here the value is prime so strong case is faster at evaluating it
29//!   assert!(4294967291f64.strong_case());
30//!  // Another strong case
31//!  assert!(!(10570841f64*10570849f64).strong_case());
32//! ```
33
34//#![feature(generic_const_items)]
35
36pub(crate) mod ptrait;
37pub(crate) mod func;
38pub(crate) mod prim;
39pub(crate) mod sets;
40pub(crate) mod iterators;
41
42
43pub use crate::ptrait::Primality;
44pub use crate::func::*;
45pub use crate::iterators::*;
46pub use crate::sets::*;