Project: Number of Primes (Estimate)
The number of primes equal to or less than a number x is denoted by the function `π(x)`. There is no easy way to compute this function although there are ways to estimate it. Write a function `π(x)` that uses the estimate formula `x/(ln x - 1)`. Assert that values of x must be greater to or equal to 100. Write a test program to print the estimated values of `π(x)` for x that are powers of 10 from `10^2` up to `10^9`. How does this approach compare to the actual value of `π(x)`?
See [[How Many Primes Are There?]]
Output
$ rustc NumberOfPrimesEstimate.rs
error: unknown format trait `d`
--> NumberOfPrimesEstimate.rs:21:33
|
21 | println!("{}", format!("π({0:d}) = {1:d}", x, π(x)));
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error: unknown format trait `d`
--> NumberOfPrimesEstimate.rs:21:42
|
21 | println!("{}", format!("π({0:d}) = {1:d}", x, π(x)));
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
warning: the usage of Script Group `Greek` in this crate consists solely of mixed script confusables
--> NumberOfPrimesEstimate.rs:10:4
|
10 | fn π(x:isize) -> i64 {
| ^
|
= note: the usage includes 'π' (U+03C0)
= note: please recheck to make sure their usages are indeed what you want
= note: `#[warn(mixed_script_confusables)]` on by default
error[E0277]: the trait bound `f64: From<isize>` is not satisfied
--> NumberOfPrimesEstimate.rs:12:26
|
12 | return (round(f64::from(x) / (log((x) as f64) - 1.0f64))) as i64;
| --------- ^ the trait `From<isize>` is not implemented for `f64`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
<f64 as From<bool>>
<f64 as From<f32>>
<f64 as From<i16>>
<f64 as From<i32>>
<f64 as From<i8>>
<f64 as From<u16>>
<f64 as From<u32>>
<f64 as From<u8>>
error[E0061]: this function takes 1 argument but 0 arguments were supplied
--> NumberOfPrimesEstimate.rs:12:32
|
12 | return (round(f64::from(x) / (log((x) as f64) - 1.0f64))) as i64;
| ^^^ an argument of type `f64` is missing
|
note: method defined here
--> /opt/local/libexec/rust/src/rustc-1.71.1-src/library/std/src/f64.rs:482:12
help: provide the argument
|
12 | return (round(f64::from(x) / (log(/* f64 */)((x) as f64) - 1.0f64))) as i64;
| +++++++++++
error[E0425]: cannot find function `log` in this scope
--> NumberOfPrimesEstimate.rs:12:32
|
12 | return (round(f64::from(x) / (log((x) as f64) - 1.0f64))) as i64;
| ^^^ not found in this scope
|
help: use the `.` operator to call the method `log` on `f64`
|
12 | return (round(f64::from(x) / (((x) as f64).log() - 1.0f64))) as i64;
| ~ ~~~~~~~
error[E0425]: cannot find function `round` in this scope
--> NumberOfPrimesEstimate.rs:12:10
|
12 | return (round(f64::from(x) / (log((x) as f64) - 1.0f64))) as i64;
| ^^^^^ not found in this scope
|
help: use the `.` operator to call the method `round` on `f64`
|
12 | return ((f64::from(x) / (log((x) as f64) - 1.0f64)).round() as i64;
| ~ ~~~~~~~~~
error: aborting due to 6 previous errors; 1 warning emitted
Some errors have detailed explanations: E0061, E0277, E0425.
For more information about an error, try `rustc --explain E0061`.