From 8313cec59795fc9eee9d073fe6bd1a18db4e53bd Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 14 Sep 2017 01:57:52 +0200 Subject: [PATCH] Extend the Float trait by some constants and supertraits --- src/float/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/float/mod.rs b/src/float/mod.rs index 33e1479..23aef32 100644 --- a/src/float/mod.rs +++ b/src/float/mod.rs @@ -1,4 +1,5 @@ use core::mem; +use core::ops; use super::int::Int; @@ -8,10 +9,23 @@ pub mod pow; pub mod sub; /// Trait for some basic operations on floats -pub trait Float: Sized + Copy { +pub trait Float: + Copy + + PartialEq + + PartialOrd + + ops::AddAssign + + ops::MulAssign + + ops::Add + + ops::Sub + + ops::Div + + ops::Rem + +{ /// A uint of the same with as the float type Int: Int; + const ZERO: Self; + const ONE: Self; + /// The bitwidth of the float type const BITS: u32; @@ -64,6 +78,9 @@ macro_rules! float_impl { ($ty:ident, $ity:ident, $bits:expr, $significand_bits:expr) => { impl Float for $ty { type Int = $ity; + const ZERO: Self = 0.0; + const ONE: Self = 1.0; + const BITS: u32 = $bits; const SIGNIFICAND_BITS: u32 = $significand_bits;