Clippy fixes

This commit is contained in:
gaxler
2021-01-30 19:55:04 -08:00
parent 2f03c1d6d7
commit ca0816db97
3 changed files with 9 additions and 10 deletions
+6 -8
View File
@@ -1,11 +1,12 @@
//! Traits to indicate that float variables can be viewed as categorical
//! This module assumes
//! This module assumes
use crate::math::num::RealNumber;
pub type CategoricalFloat = u16;
// pub struct CategoricalFloat(u16);
const ERROR_MARGIN: f64 = 0.001;
pub trait Categorizable: RealNumber {
type A;
@@ -13,11 +14,9 @@ pub trait Categorizable: RealNumber {
fn to_category(self) -> CategoricalFloat;
fn is_valid(self) -> bool;
}
impl Categorizable for f32 {
type A = CategoricalFloat;
fn to_category(self) -> CategoricalFloat {
@@ -26,20 +25,19 @@ impl Categorizable for f32 {
fn is_valid(self) -> bool {
let a = self.to_category();
a as f32 == self
(a as f32 - self).abs() < (ERROR_MARGIN as f32)
}
}
impl Categorizable for f64 {
type A = CategoricalFloat;
fn to_category(self) ->CategoricalFloat {
fn to_category(self) -> CategoricalFloat {
self as CategoricalFloat
}
fn is_valid(self) -> bool {
let a = self.to_category();
a as f64 == self
(a as f64 - self).abs() < ERROR_MARGIN
}
}
}