File tree 3 files changed +96
-98
lines changed
3 files changed +96
-98
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,20 @@ pub enum FullDecoded {
53
53
54
54
/// A floating point type which can be `decode`d.
55
55
pub trait DecodableFloat : Float + Copy {
56
+ /// Returns `x * 2^exp`. Almost same to `std::{f32,f64}::ldexp`.
57
+ /// This is used for testing.
58
+ fn ldexpi ( f : i64 , exp : isize ) -> Self ;
56
59
/// The minimum positive normalized value.
57
60
fn min_pos_norm_value ( ) -> Self ;
58
61
}
59
62
60
63
impl DecodableFloat for f32 {
64
+ fn ldexpi ( f : i64 , exp : isize ) -> Self { f as Self * ( exp as Self ) . exp2 ( ) }
61
65
fn min_pos_norm_value ( ) -> Self { f32:: MIN_POSITIVE }
62
66
}
63
67
64
68
impl DecodableFloat for f64 {
69
+ fn ldexpi ( f : i64 , exp : isize ) -> Self { f as Self * ( exp as Self ) . exp2 ( ) }
65
70
fn min_pos_norm_value ( ) -> Self { f64:: MIN_POSITIVE }
66
71
}
67
72
Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use std:: num :: Float ;
11
+ use std:: f64 ;
12
12
use core:: num:: flt2dec:: estimator:: * ;
13
13
14
14
#[ test]
@@ -54,7 +54,7 @@ fn test_estimate_scaling_factor() {
54
54
assert_almost_eq ! ( estimate_scaling_factor( 0x1fffffffffffff , 971 ) , 309 ) ;
55
55
56
56
for i in -1074 ..972 {
57
- let expected = Float :: ldexp ( 1.0 , i) . log10 ( ) . ceil ( ) ;
57
+ let expected = f64 :: ldexp ( 1.0 , i) . log10 ( ) . ceil ( ) ;
58
58
assert_almost_eq ! ( estimate_scaling_factor( 1 , i as i16 ) , expected as i16 ) ;
59
59
}
60
60
}
You can’t perform that action at this time.
0 commit comments