From f3f56ed5f183f8461cc91cb6430d97c725ba159c Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Feb 2021 00:37:58 +0100 Subject: Move to double to avoid rounding error This rounding errors seems to happen when adding floats very close to 1 to a relatively large number. 325.0 + 0.99999034 = 326.0 This is a problem as this sample should be counted at the 325 pixel. However this will be a lesser problem when filtering is implemented. --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 0ec6700..7da6627 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod sample; use std::ops::{Add, Sub, Mul, DivAssign, Neg}; use std::cmp; use std::fmt; +use std::f64::consts::PI; /// Trait used to implement generics /// @@ -25,8 +26,11 @@ pub trait Number: impl Number for i32 {} impl Number for f32 {} +impl Number for f64 {} /// Used for representing floating point values throughout the program /// /// A higher precision type will require more ram -pub type Float = f32; +pub type Float = f64; + +pub const M_PI: Float = PI; -- cgit v1.2.3