@@ -685,13 +685,13 @@ struct F64UiFormatter {
685685}
686686
687687impl F64UiFormatter {
688- fn new ( num_significant_digits : i32 ) -> Self {
688+ fn new ( num_significant_digits : usize ) -> Self {
689689 let options = lexical_write_float:: Options :: builder ( )
690- . max_significant_digits ( core:: num:: NonZeroUsize :: new (
691- num_significant_digits as usize ,
690+ . max_significant_digits ( core:: num:: NonZeroUsize :: new ( num_significant_digits) )
691+ . positive_exponent_break ( core:: num:: NonZeroI32 :: new ( num_significant_digits as i32 ) )
692+ . negative_exponent_break ( core:: num:: NonZeroI32 :: new (
693+ -( num_significant_digits as i32 ) + 1 ,
692694 ) )
693- . positive_exponent_break ( core:: num:: NonZeroI32 :: new ( num_significant_digits) )
694- . negative_exponent_break ( core:: num:: NonZeroI32 :: new ( -num_significant_digits + 1 ) )
695695 . trim_floats ( true )
696696 . build_strict ( ) ;
697697
@@ -2233,4 +2233,23 @@ q_1: ┤ Rz(1.2346e8) ├┤ Rx(0.12346) ├┤ Rx(1.2346e-5) ├
22332233 assert_eq ! ( format_float_pi( test. 0 ) , test. 1 . map( |s| s. to_string( ) ) ) ;
22342234 }
22352235 }
2236+
2237+ #[ test]
2238+ fn test_f64_ui_formatter ( ) {
2239+ let test_data_5_sig_digits = [
2240+ ( -1.23 , "-1.23" ) ,
2241+ ( 1.23456 , "1.2346" ) ,
2242+ ( -12.34567 , "-12.346" ) ,
2243+ ( 123456.78 , "123460" ) ,
2244+ ( -0.0001 , "-0.0001" ) ,
2245+ ( 12.34 * 1_000_000.0 , "1.234e7" ) ,
2246+ ( -0.00001 , "-1e-5" ) ,
2247+ ( 12345678.000001 , "1.2346e7" ) ,
2248+ ] ;
2249+
2250+ let mut formatter = F64UiFormatter :: new ( 5 ) ;
2251+ for test in test_data_5_sig_digits {
2252+ assert_eq ! ( test. 1 , formatter. format( test. 0 ) ) ;
2253+ }
2254+ }
22362255}
0 commit comments