Project: Compute π Function
Write a function that computes and returns the value π which can be easily computed with standard math functions using one of the formula:
- atan(1.0)*4.0
- atan2(0.0, -1.0)
- acos(-1.0)
- 2.0*acos(0.0)
See [[Pi]]
Output
$ rustc ComputePi3.rs
error: unknown format trait `f`
--> ComputePi3.rs:15:36
|
15 | println!("{}", format!("PI: {0:.15f}", PI));
| ^
|
= 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: unused import: `std::f64::consts`
--> ComputePi3.rs:7:5
|
7 | use std::f64::consts;
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0425]: cannot find function `acos` in this scope
--> ComputePi3.rs:10:18
|
10 | return 2.0f64 * acos(0.0f64);
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `acos` on `f64`
|
10 - return 2.0f64 * acos(0.0f64);
10 + return 2.0f64 * 0.0f64.acos();
|
error[E0425]: cannot find function `fabs` in this scope
--> ComputePi3.rs:16:50
|
16 | println!("{}", format!("abs(PI - π): {0:.10e}", fabs(PI - PI)));
| ^^^^ not found in this scope
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0425`.