1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// devela::num::dom::int::fns
use crateFloatExt;
/// The prime number theorem formula.
///
/// Returns the approximate count of primes less than the given `n`.
///
/// $$ \large \pi(x) \sim \frac{x}{\ln(x)} $$
///
/// # Examples
/// ```
/// use devela::num::prime_number_theorem as pi;
///
/// // Showing the % difference against the real amount, if known.
/// // Note how precision increases in direct relationship to the power.
/// assert_eq![pi(u8::MAX.into()), 46]; // 14.81% < 54
/// assert_eq![pi(u16::MAX.into()), 5909]; // 9.67% < 6542
///
/// #[cfg(feature = "std")] // too slow otherwise
/// # #[cfg(not(miri))] // ln() is non-deterministic
/// {
/// assert_eq![pi(u32::MAX.into()), 193635251]; // 4.74% < 203280221
/// assert_eq![pi(u64::MAX.into()), 415828534307635072]; // 2.30% < 425656284035217743
/// assert_eq![pi(2u128.pow(92)), 77650867634561160386183168]; // 1.59% < 78908656317357166866404346
/// assert_eq![pi(u128::MAX.into()), 3835341275459348115779911081237938176]; // ?% < ?
/// }
/// ```
/// # Links
/// - <https://mathworld.wolfram.com/PrimeNumberTheorem.html>
/// - <https://en.wikipedia.org/wiki/Prime_number_theorem>
/// - The exact prime count till $2^{92}$ is available in <https://oeis.org/A007053>.
//
// IMPROVE: use big int and big float.