mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2025-02-16 20:28:27 +00:00
Added more tests for rand regarding relative error
This commit is contained in:
parent
d6d52824d2
commit
191aab4810
1 changed files with 5 additions and 1 deletions
|
@ -62,7 +62,11 @@ fn monte_carlo(a: f32, b: f32, n: u32) -> f32 {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", monte_carlo(0., f32::consts::PI, 200_000));
|
||||
let actual = 2.0;
|
||||
let estimate = monte_carlo(0., f32::consts::PI, 200_000);
|
||||
let rel_err = (estimate - actual) / actual;
|
||||
assert!(rel_err < 10e-3);
|
||||
println!("{}", estimate);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue