File tree Expand file tree Collapse file tree 3 files changed +96
-98
lines changed Expand file tree Collapse file tree 3 files changed +96
-98
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,20 @@ pub enum FullDecoded {
5353
5454/// A floating point type which can be `decode`d.
5555pub 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 ;
5659 /// The minimum positive normalized value.
5760 fn min_pos_norm_value ( ) -> Self ;
5861}
5962
6063impl DecodableFloat for f32 {
64+ fn ldexpi ( f : i64 , exp : isize ) -> Self { f as Self * ( exp as Self ) . exp2 ( ) }
6165 fn min_pos_norm_value ( ) -> Self { f32:: MIN_POSITIVE }
6266}
6367
6468impl DecodableFloat for f64 {
69+ fn ldexpi ( f : i64 , exp : isize ) -> Self { f as Self * ( exp as Self ) . exp2 ( ) }
6570 fn min_pos_norm_value ( ) -> Self { f64:: MIN_POSITIVE }
6671}
6772
Original file line number Diff line number Diff line change 88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use std:: num :: Float ;
11+ use std:: f64 ;
1212use core:: num:: flt2dec:: estimator:: * ;
1313
1414#[ test]
@@ -54,7 +54,7 @@ fn test_estimate_scaling_factor() {
5454 assert_almost_eq ! ( estimate_scaling_factor( 0x1fffffffffffff , 971 ) , 309 ) ;
5555
5656 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 ( ) ;
5858 assert_almost_eq ! ( estimate_scaling_factor( 1 , i as i16 ) , expected as i16 ) ;
5959 }
6060}
You can’t perform that action at this time.
0 commit comments