@@ -6,6 +6,8 @@ use core::num::fmt::{Formatted, Part};
6
6
use std:: mem:: MaybeUninit ;
7
7
use std:: { fmt, str} ;
8
8
9
+ use crate :: num:: { ldexp_f32, ldexp_f64} ;
10
+
9
11
mod estimator;
10
12
mod strategy {
11
13
mod dragon;
@@ -75,24 +77,6 @@ macro_rules! try_fixed {
75
77
} )
76
78
}
77
79
78
- #[ cfg( target_has_reliable_f16) ]
79
- fn ldexp_f16 ( a : f16 , b : i32 ) -> f16 {
80
- ldexp_f64 ( a as f64 , b) as f16
81
- }
82
-
83
- fn ldexp_f32 ( a : f32 , b : i32 ) -> f32 {
84
- ldexp_f64 ( a as f64 , b) as f32
85
- }
86
-
87
- fn ldexp_f64 ( a : f64 , b : i32 ) -> f64 {
88
- unsafe extern "C" {
89
- fn ldexp ( x : f64 , n : i32 ) -> f64 ;
90
- }
91
- // SAFETY: assuming a correct `ldexp` has been supplied, the given arguments cannot possibly
92
- // cause undefined behavior
93
- unsafe { ldexp ( a, b) }
94
- }
95
-
96
80
fn check_exact < F , T > ( mut f : F , v : T , vstr : & str , expected : & [ u8 ] , expectedk : i16 )
97
81
where
98
82
T : DecodableFloat ,
@@ -268,7 +252,7 @@ where
268
252
// 10^2 * 0.31984375
269
253
// 10^2 * 0.32
270
254
// 10^2 * 0.3203125
271
- check_shortest ! ( f( ldexp_f16( 1.0 , 5 ) ) => b"32" , 2 ) ;
255
+ check_shortest ! ( f( crate :: num :: ldexp_f16( 1.0 , 5 ) ) => b"32" , 2 ) ;
272
256
273
257
// 10^5 * 0.65472
274
258
// 10^5 * 0.65504
@@ -283,7 +267,7 @@ where
283
267
// 10^-9 * 0
284
268
// 10^-9 * 0.59604644775390625
285
269
// 10^-8 * 0.11920928955078125
286
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
270
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
287
271
check_shortest ! ( f( minf16) => b"6" , -7 ) ;
288
272
}
289
273
@@ -292,7 +276,7 @@ pub fn f16_exact_sanity_test<F>(mut f: F)
292
276
where
293
277
F : for < ' a > FnMut ( & Decoded , & ' a mut [ MaybeUninit < u8 > ] , i16 ) -> ( & ' a [ u8 ] , i16 ) ,
294
278
{
295
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
279
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
296
280
297
281
check_exact ! ( f( 0.1f16 ) => b"999755859375 " , -1 ) ;
298
282
check_exact ! ( f( 0.5f16 ) => b"5 " , 0 ) ;
@@ -642,7 +626,7 @@ where
642
626
assert_eq ! ( to_string( f, f16:: MAX , Minus , 1 ) , "65500.0" ) ;
643
627
assert_eq ! ( to_string( f, f16:: MAX , Minus , 8 ) , "65500.00000000" ) ;
644
628
645
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
629
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
646
630
assert_eq ! ( to_string( f, minf16, Minus , 0 ) , "0.00000006" ) ;
647
631
assert_eq ! ( to_string( f, minf16, Minus , 8 ) , "0.00000006" ) ;
648
632
assert_eq ! ( to_string( f, minf16, Minus , 9 ) , "0.000000060" ) ;
@@ -766,7 +750,7 @@ where
766
750
assert_eq ! ( to_string( f, f16:: MAX , Minus , ( -4 , 4 ) , false ) , "6.55e4" ) ;
767
751
assert_eq ! ( to_string( f, f16:: MAX , Minus , ( -5 , 5 ) , false ) , "65500" ) ;
768
752
769
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
753
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
770
754
assert_eq ! ( to_string( f, minf16, Minus , ( -2 , 2 ) , false ) , "6e-8" ) ;
771
755
assert_eq ! ( to_string( f, minf16, Minus , ( -7 , 7 ) , false ) , "6e-8" ) ;
772
756
assert_eq ! ( to_string( f, minf16, Minus , ( -8 , 8 ) , false ) , "0.00000006" ) ;
@@ -922,7 +906,7 @@ where
922
906
assert_eq ! ( to_string( f, f16:: MAX , Minus , 6 , false ) , "6.55040e4" ) ;
923
907
assert_eq ! ( to_string( f, f16:: MAX , Minus , 16 , false ) , "6.550400000000000e4" ) ;
924
908
925
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
909
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
926
910
assert_eq ! ( to_string( f, minf16, Minus , 1 , false ) , "6e-8" ) ;
927
911
assert_eq ! ( to_string( f, minf16, Minus , 2 , false ) , "6.0e-8" ) ;
928
912
assert_eq ! ( to_string( f, minf16, Minus , 4 , false ) , "5.960e-8" ) ;
@@ -1229,7 +1213,7 @@ where
1229
1213
1230
1214
#[ cfg( target_has_reliable_f16) ]
1231
1215
{
1232
- let minf16 = ldexp_f16 ( 1.0 , -24 ) ;
1216
+ let minf16 = crate :: num :: ldexp_f16 ( 1.0 , -24 ) ;
1233
1217
assert_eq ! ( to_string( f, minf16, Minus , 0 ) , "0" ) ;
1234
1218
assert_eq ! ( to_string( f, minf16, Minus , 1 ) , "0.0" ) ;
1235
1219
assert_eq ! ( to_string( f, minf16, Minus , 2 ) , "0.00" ) ;
0 commit comments