11use core:: { fmt, mem, ops} ;
22
3- use super :: int_traits:: { Int , MinInt } ;
3+ use super :: int_traits:: { CastInto , Int , MinInt } ;
44
55/// Trait for some basic operations on floats
66#[ allow( dead_code) ]
@@ -25,9 +25,6 @@ pub trait Float:
2525 /// A int of the same width as the float
2626 type SignedInt : Int + MinInt < OtherSign = Self :: Int , Unsigned = Self :: Int > ;
2727
28- /// An int capable of containing the exponent bits plus a sign bit. This is signed.
29- type ExpInt : Int ;
30-
3128 const ZERO : Self ;
3229 const NEG_ZERO : Self ;
3330 const ONE : Self ;
@@ -98,7 +95,9 @@ pub trait Float:
9895 }
9996
10097 /// Returns the exponent, not adjusting for bias.
101- fn exp ( self ) -> Self :: ExpInt ;
98+ fn exp ( self ) -> i32 {
99+ ( ( self . to_bits ( ) & Self :: EXP_MASK ) >> Self :: SIG_BITS ) . cast ( )
100+ }
102101
103102 /// Returns the significand with no implicit bit (or the "fractional" part)
104103 fn frac ( self ) -> Self :: Int {
@@ -146,15 +145,13 @@ macro_rules! float_impl {
146145 $ty: ident,
147146 $ity: ident,
148147 $sity: ident,
149- $expty: ident,
150148 $bits: expr,
151149 $significand_bits: expr,
152150 $from_bits: path
153151 ) => {
154152 impl Float for $ty {
155153 type Int = $ity;
156154 type SignedInt = $sity;
157- type ExpInt = $expty;
158155
159156 const ZERO : Self = 0.0 ;
160157 const NEG_ZERO : Self = -0.0 ;
@@ -191,9 +188,6 @@ macro_rules! float_impl {
191188 fn is_sign_negative( self ) -> bool {
192189 self . is_sign_negative( )
193190 }
194- fn exp( self ) -> Self :: ExpInt {
195- ( ( self . to_bits( ) & Self :: EXP_MASK ) >> Self :: SIG_BITS ) as Self :: ExpInt
196- }
197191 fn from_bits( a: Self :: Int ) -> Self {
198192 Self :: from_bits( a)
199193 }
@@ -226,11 +220,11 @@ macro_rules! float_impl {
226220}
227221
228222#[ cfg( f16_enabled) ]
229- float_impl ! ( f16, u16 , i16 , i8 , 16 , 10 , f16:: from_bits) ;
230- float_impl ! ( f32 , u32 , i32 , i16 , 32 , 23 , f32_from_bits) ;
231- float_impl ! ( f64 , u64 , i64 , i16 , 64 , 52 , f64_from_bits) ;
223+ float_impl ! ( f16, u16 , i16 , 16 , 10 , f16:: from_bits) ;
224+ float_impl ! ( f32 , u32 , i32 , 32 , 23 , f32_from_bits) ;
225+ float_impl ! ( f64 , u64 , i64 , 64 , 52 , f64_from_bits) ;
232226#[ cfg( f128_enabled) ]
233- float_impl ! ( f128, u128 , i128 , i16 , 128 , 112 , f128:: from_bits) ;
227+ float_impl ! ( f128, u128 , i128 , 128 , 112 , f128:: from_bits) ;
234228
235229/* FIXME(msrv): vendor some things that are not const stable at our MSRV */
236230
0 commit comments