make float range more readable

This commit is contained in:
jacekpoz 2023-11-05 20:29:29 +01:00
parent fe3a534eff
commit 662d78be06
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C

View file

@ -39,16 +39,17 @@ fn points_under_graph(
fn get_sup( fn get_sup(
integral: &Integral<f64> integral: &Integral<f64>
) -> f64 { ) -> f64 {
let multiplier = 1000.0;
let b = &integral.bounds; let b = &integral.bounds;
let f = &integral.function; let f = &integral.function;
let mut sup = f(b.start); let mut sup = f(b.start);
for i in // needed to iterate over a float range with some step
(((b.start * multiplier) as i64)..((b.end * multiplier) as i64)) let multiplier = 1000.0;
.map(|x| (x as f64) / multiplier) let start_int = (b.start * multiplier) as i64;
{ let end_it = (b.end * multiplier) as i64;
for i in (start_int..end_it).map(|x| (x as f64) / multiplier) {
let y = f(i); let y = f(i);
// for the π approximation f(-1) and f(1) // for the π approximation f(-1) and f(1)
// returned ∞, this if fixes that // returned ∞, this if fixes that