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

Improve are_primes_below example #9

Merged
merged 6 commits into from
Oct 1, 2023
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ assert_eq!(PRIME_STATUS, [false, false, true, true, false, true, false, true, fa
```
or `are_prime_below` to compute the prime status of the `N` largest integers below a given value,
```rust
const N: usize = 1001;
const BIG_PRIME_STATUS: [bool; N] = are_prime_below(1_000_005);
// 1_000_002 1_000_003 1_000_004
assert_eq!(BIG_PRIME_STATUS[998..], [false, true, false]);
const N: usize = 70711;
const BIG_PRIME_STATUS: [bool; N] = are_prime_below(5_000_000_031);
// 5_000_000_028 5_000_000_029 5_000_000_030
assert_eq!(BIG_PRIME_STATUS[N - 3..], [false, true, false]);
```
and more!

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@
//! or [`are_prime_below`] to compute the prime status of the `N` largest integers below a given value,
//! ```
//! # use const_primes::are_prime_below;
//! const N: usize = 1001;
//! const BIG_PRIME_STATUS: [bool; N] = are_prime_below(1_000_005);
//! // 1_000_002 1_000_003 1_000_004
//! assert_eq!(BIG_PRIME_STATUS[998..], [false, true, false]);
//! const N: usize = 70711;
//! const BIG_PRIME_STATUS: [bool; N] = are_prime_below(5_000_000_031);
//! // 5_000_000_028 5_000_000_029 5_000_000_030
//! assert_eq!(BIG_PRIME_STATUS[N - 3..], [false, true, false]);
//! ```
//! and more!

#![forbid(unsafe_code)]
#![cfg_attr(not(test), no_std)]

/// The functions that return or take integers use this type. Currently `u32`.
/// The type that Primes<N> stores, and primes::<N>() returns. Currently `u32`.
// Just change this to whatever unsigned primitive integer type you want and it should work as long as it has enough bits for your purposes.
// This is used since there is currently no way to be generic over types that can do arithmetic at compile time.
type Underlying = u32;
Expand Down