@@ -21,13 +21,14 @@ macro_rules! check {
2121 check!( $ty, $s, core:: $ty:: NEG_INFINITY )
2222 } } ;
2323 ( $ty: ident, $s: expr, $e: expr) => { {
24- let s = $s. as_bytes( ) ;
24+ let string = String :: from( $s) ;
25+ let s = string. as_bytes( ) ;
2526 let expected: $ty = $e;
2627 let result = fast_float:: parse:: <$ty, _>( s) . unwrap( ) ;
2728 assert_eq!( result, expected) ;
2829 let lex = lexical_core:: parse:: <$ty>( s) . unwrap( ) ;
2930 assert_eq!( result, lex) ;
30- let std = <$ty>:: from_str( $s ) ;
31+ let std = <$ty>:: from_str( string . as_str ( ) ) ;
3132 if let Ok ( std) = std {
3233 // stdlib can't parse all weird floats
3334 if std. is_finite( ) && result. is_finite( ) {
@@ -84,6 +85,14 @@ macro_rules! check_f64_neg_inf {
8485 } ;
8586}
8687
88+ fn append_zeros ( s : impl AsRef < str > , n : usize ) -> String {
89+ let mut s = String :: from ( s. as_ref ( ) ) ;
90+ for _ in 0 ..n {
91+ s. push ( '0' ) ;
92+ }
93+ s
94+ }
95+
8796#[ test]
8897fn test_f64_inf ( ) {
8998 check_f64_inf ! ( "INF" ) ;
@@ -200,6 +209,17 @@ fn test_f64_long() {
200209
201210#[ test]
202211fn test_f64_general ( ) {
212+ check_f64 ! ( "9007199254740993.0" , hexf64( "0x1.p+53" ) ) ;
213+ check_f64 ! ( append_zeros( "9007199254740993.0" , 1000 ) , hexf64( "0x1.p+53" ) ) ;
214+ check_f64 ! ( "10000000000000000000" , hexf64( "0x1.158e460913dp+63" ) ) ;
215+ check_f64 ! (
216+ "10000000000000000000000000000001000000000000" ,
217+ hexf64( "0x1.cb2d6f618c879p+142" )
218+ ) ;
219+ check_f64 ! (
220+ "10000000000000000000000000000000000000000001" ,
221+ hexf64( "0x1.cb2d6f618c879p+142" )
222+ ) ;
203223 check_f64 ! ( 1.1920928955078125e-07 ) ;
204224 check_f64 ! ( "-0" , -0.0 ) ;
205225 check_f64 ! (
@@ -277,6 +297,23 @@ fn test_f32_inf() {
277297
278298#[ test]
279299fn test_f32_basic ( ) {
300+ let f1 = "\
301+ 1.175494140627517859246175898662808184331245864732796240031385942718174675986064\
302+ 7699724722770042717456817626953125";
303+ check_f32 ! ( f1, hexf32( "0x1.2ced3p+0" ) ) ;
304+ check_f32 ! ( format!( "{}e-38" , f1) , hexf32( "0x1.fffff8p-127" ) ) ;
305+ check_f32 ! (
306+ format!( "{}e-38" , append_zeros( f1, 655 ) ) ,
307+ hexf32( "0x1.fffff8p-127" )
308+ ) ;
309+ check_f32 ! (
310+ format!( "{}e-38" , append_zeros( f1, 656 ) ) ,
311+ hexf32( "0x1.fffff8p-127" )
312+ ) ;
313+ check_f32 ! (
314+ format!( "{}e-38" , append_zeros( f1, 1000 ) ) ,
315+ hexf32( "0x1.fffff8p-127" )
316+ ) ;
280317 check_f32 ! ( 1.00000006e+09 ) ;
281318 check_f32 ! ( 1.4012984643e-45 ) ;
282319 check_f32 ! ( 1.1754942107e-38 ) ;
0 commit comments