diff --git a/src/lmath.rc b/src/lmath.rc index 7e1749f..2b2fc55 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -31,6 +31,7 @@ pub mod common { pub mod num { pub mod cast; pub mod consts; + pub mod default_eq; pub mod ext; } diff --git a/src/num/default_eq.rs b/src/num/default_eq.rs new file mode 100644 index 0000000..4d1036f --- /dev/null +++ b/src/num/default_eq.rs @@ -0,0 +1,24 @@ +use std::cmp::FuzzyEq; + + +pub trait DefaultEq { + pure fn default_eq(other: &self) -> bool; +} + +pub impl bool: DefaultEq { #[inline(always)] pure fn default_eq(other: &bool) -> bool { self == *other } } + +pub impl u8: DefaultEq { #[inline(always)] pure fn default_eq(other: &u8) -> bool { self == *other } } +pub impl u16: DefaultEq { #[inline(always)] pure fn default_eq(other: &u16) -> bool { self == *other } } +pub impl u32: DefaultEq { #[inline(always)] pure fn default_eq(other: &u32) -> bool { self == *other } } +pub impl u64: DefaultEq { #[inline(always)] pure fn default_eq(other: &u64) -> bool { self == *other } } +pub impl uint: DefaultEq { #[inline(always)] pure fn default_eq(other: &uint) -> bool { self == *other } } + +pub impl i8: DefaultEq { #[inline(always)] pure fn default_eq(other: &i8) -> bool { self == *other } } +pub impl i16: DefaultEq { #[inline(always)] pure fn default_eq(other: &i16) -> bool { self == *other } } +pub impl i32: DefaultEq { #[inline(always)] pure fn default_eq(other: &i32) -> bool { self == *other } } +pub impl i64: DefaultEq { #[inline(always)] pure fn default_eq(other: &i64) -> bool { self == *other } } +pub impl int: DefaultEq { #[inline(always)] pure fn default_eq(other: &int) -> bool { self == *other } } + +pub impl f32: DefaultEq { #[inline(always)] pure fn default_eq(other: &f32) -> bool { self.fuzzy_eq(other) } } +pub impl f64: DefaultEq { #[inline(always)] pure fn default_eq(other: &f64) -> bool { self.fuzzy_eq(other) } } +pub impl float: DefaultEq { #[inline(always)] pure fn default_eq(other: &float) -> bool { self.fuzzy_eq(other) } } \ No newline at end of file