From 662d78be065fc2f2908e248f007be1aafdffe188 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 5 Nov 2023 20:29:29 +0100 Subject: [PATCH] make float range more readable --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 852db25..f8e24aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,16 +39,17 @@ fn points_under_graph( fn get_sup( integral: &Integral ) -> f64 { - let multiplier = 1000.0; let b = &integral.bounds; let f = &integral.function; let mut sup = f(b.start); + + // needed to iterate over a float range with some step + let multiplier = 1000.0; + let start_int = (b.start * multiplier) as i64; + let end_it = (b.end * multiplier) as i64; - for i in - (((b.start * multiplier) as i64)..((b.end * multiplier) as i64)) - .map(|x| (x as f64) / multiplier) - { + for i in (start_int..end_it).map(|x| (x as f64) / multiplier) { let y = f(i); // for the π approximation f(-1) and f(1) // returned ∞, this if fixes that