@@ -33,7 +33,7 @@ use ops::{Add, Mul, Div, Neg};
33
33
use fmt:: { Debug , LowerExp } ;
34
34
use num:: diy_float:: Fp ;
35
35
use num:: FpCategory :: { Infinite , Zero , Subnormal , Normal , Nan } ;
36
- use num:: Float ;
36
+ use num:: FpCategory ;
37
37
use num:: dec2flt:: num:: { self , Big } ;
38
38
use num:: dec2flt:: table;
39
39
@@ -54,24 +54,29 @@ impl Unpacked {
54
54
/// See the parent module's doc comment for why this is necessary.
55
55
///
56
56
/// Should **never ever** be implemented for other types or be used outside the dec2flt module.
57
- /// Inherits from `Float` because there is some overlap, but all the reused methods are trivial.
58
57
pub trait RawFloat
59
- : Float
60
- + Copy
58
+ : Copy
61
59
+ Debug
62
60
+ LowerExp
63
61
+ Mul < Output =Self >
64
62
+ Div < Output =Self >
65
63
+ Neg < Output =Self >
66
- where
67
- Self : Float < Bits = <Self as RawFloat >:: RawBits >
68
64
{
69
65
const INFINITY : Self ;
70
66
const NAN : Self ;
71
67
const ZERO : Self ;
72
68
73
- /// Same as `Float::Bits` with extra traits.
74
- type RawBits : Add < Output = Self :: RawBits > + From < u8 > + TryFrom < u64 > ;
69
+ /// Type used by `to_bits` and `from_bits`.
70
+ type Bits : Add < Output = Self :: Bits > + From < u8 > + TryFrom < u64 > ;
71
+
72
+ /// Raw transmutation to integer.
73
+ fn to_bits ( self ) -> Self :: Bits ;
74
+
75
+ /// Raw transmutation from integer.
76
+ fn from_bits ( v : Self :: Bits ) -> Self ;
77
+
78
+ /// Returns the category that this number falls into.
79
+ fn classify ( self ) -> FpCategory ;
75
80
76
81
/// Returns the mantissa, exponent and sign as integers.
77
82
fn integer_decode ( self ) -> ( u64 , i16 , i8 ) ;
@@ -153,7 +158,7 @@ macro_rules! other_constants {
153
158
}
154
159
155
160
impl RawFloat for f32 {
156
- type RawBits = u32 ;
161
+ type Bits = u32 ;
157
162
158
163
const SIG_BITS : u8 = 24 ;
159
164
const EXP_BITS : u8 = 8 ;
@@ -192,11 +197,15 @@ impl RawFloat for f32 {
192
197
fn short_fast_pow10 ( e : usize ) -> Self {
193
198
table:: F32_SHORT_POWERS [ e]
194
199
}
200
+
201
+ fn classify ( self ) -> FpCategory { self . classify ( ) }
202
+ fn to_bits ( self ) -> Self :: Bits { self . to_bits ( ) }
203
+ fn from_bits ( v : Self :: Bits ) -> Self { Self :: from_bits ( v) }
195
204
}
196
205
197
206
198
207
impl RawFloat for f64 {
199
- type RawBits = u64 ;
208
+ type Bits = u64 ;
200
209
201
210
const SIG_BITS : u8 = 53 ;
202
211
const EXP_BITS : u8 = 11 ;
@@ -235,6 +244,10 @@ impl RawFloat for f64 {
235
244
fn short_fast_pow10 ( e : usize ) -> Self {
236
245
table:: F64_SHORT_POWERS [ e]
237
246
}
247
+
248
+ fn classify ( self ) -> FpCategory { self . classify ( ) }
249
+ fn to_bits ( self ) -> Self :: Bits { self . to_bits ( ) }
250
+ fn from_bits ( v : Self :: Bits ) -> Self { Self :: from_bits ( v) }
238
251
}
239
252
240
253
/// Convert an Fp to the closest machine float type.
0 commit comments