2828//! take the universally-correct slow path (Algorithm M) for very small and very large numbers.
2929//! That algorithm needs only next_float() which does handle subnormals and zeros.
3030use cmp:: Ordering :: { Less , Equal , Greater } ;
31- use convert:: TryInto ;
32- use ops:: { Mul , Div , Neg } ;
31+ use convert:: { TryFrom , TryInto } ;
32+ use ops:: { Add , Mul , Div , Neg } ;
3333use fmt:: { Debug , LowerExp } ;
3434use num:: diy_float:: Fp ;
3535use num:: FpCategory :: { Infinite , Zero , Subnormal , Normal , Nan } ;
@@ -55,13 +55,24 @@ impl Unpacked {
5555///
5656/// Should **never ever** be implemented for other types or be used outside the dec2flt module.
5757/// Inherits from `Float` because there is some overlap, but all the reused methods are trivial.
58- pub trait RawFloat : Float + Copy + Debug + LowerExp
59- + Mul < Output =Self > + Div < Output =Self > + Neg < Output =Self >
58+ pub trait RawFloat
59+ : Float
60+ + Copy
61+ + Debug
62+ + LowerExp
63+ + Mul < Output =Self >
64+ + Div < Output =Self >
65+ + Neg < Output =Self >
66+ where
67+ Self : Float < Bits = <Self as RawFloat >:: RawBits >
6068{
6169 const INFINITY : Self ;
6270 const NAN : Self ;
6371 const ZERO : Self ;
6472
73+ /// Same as `Float::Bits` with extra traits.
74+ type RawBits : Add < Output = Self :: RawBits > + From < u8 > + TryFrom < u64 > ;
75+
6576 /// Returns the mantissa, exponent and sign as integers.
6677 fn integer_decode ( self ) -> ( u64 , i16 , i8 ) ;
6778
@@ -142,6 +153,8 @@ macro_rules! other_constants {
142153}
143154
144155impl RawFloat for f32 {
156+ type RawBits = u32 ;
157+
145158 const SIG_BITS : u8 = 24 ;
146159 const EXP_BITS : u8 = 8 ;
147160 const CEIL_LOG5_OF_MAX_SIG : i16 = 11 ;
@@ -183,6 +196,8 @@ impl RawFloat for f32 {
183196
184197
185198impl RawFloat for f64 {
199+ type RawBits = u64 ;
200+
186201 const SIG_BITS : u8 = 53 ;
187202 const EXP_BITS : u8 = 11 ;
188203 const CEIL_LOG5_OF_MAX_SIG : i16 = 23 ;
0 commit comments