1
1
use core:: { fmt, mem, ops} ;
2
2
3
- use super :: int_traits:: { Int , MinInt } ;
3
+ use super :: int_traits:: { CastInto , Int , MinInt } ;
4
4
5
5
/// Trait for some basic operations on floats
6
6
#[ allow( dead_code) ]
@@ -25,9 +25,6 @@ pub trait Float:
25
25
/// A int of the same width as the float
26
26
type SignedInt : Int + MinInt < OtherSign = Self :: Int , Unsigned = Self :: Int > ;
27
27
28
- /// An int capable of containing the exponent bits plus a sign bit. This is signed.
29
- type ExpInt : Int ;
30
-
31
28
const ZERO : Self ;
32
29
const NEG_ZERO : Self ;
33
30
const ONE : Self ;
@@ -98,7 +95,9 @@ pub trait Float:
98
95
}
99
96
100
97
/// 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
+ }
102
101
103
102
/// Returns the significand with no implicit bit (or the "fractional" part)
104
103
fn frac ( self ) -> Self :: Int {
@@ -146,15 +145,13 @@ macro_rules! float_impl {
146
145
$ty: ident,
147
146
$ity: ident,
148
147
$sity: ident,
149
- $expty: ident,
150
148
$bits: expr,
151
149
$significand_bits: expr,
152
150
$from_bits: path
153
151
) => {
154
152
impl Float for $ty {
155
153
type Int = $ity;
156
154
type SignedInt = $sity;
157
- type ExpInt = $expty;
158
155
159
156
const ZERO : Self = 0.0 ;
160
157
const NEG_ZERO : Self = -0.0 ;
@@ -191,9 +188,6 @@ macro_rules! float_impl {
191
188
fn is_sign_negative( self ) -> bool {
192
189
self . is_sign_negative( )
193
190
}
194
- fn exp( self ) -> Self :: ExpInt {
195
- ( ( self . to_bits( ) & Self :: EXP_MASK ) >> Self :: SIG_BITS ) as Self :: ExpInt
196
- }
197
191
fn from_bits( a: Self :: Int ) -> Self {
198
192
Self :: from_bits( a)
199
193
}
@@ -226,11 +220,11 @@ macro_rules! float_impl {
226
220
}
227
221
228
222
#[ 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) ;
232
226
#[ 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) ;
234
228
235
229
/* FIXME(msrv): vendor some things that are not const stable at our MSRV */
236
230
0 commit comments