File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -533,13 +533,11 @@ fn consider_suffix(
533533
534534 // check if rounding pushed us into the next base
535535 if v. abs ( ) >= bases[ 1 ] {
536- // Rounding promoted the value to the next base. When already at the
537- // largest base there is no suffix above it, so the value is too large
538- // to represent (rather than indexing `suffixes` out of bounds).
539- if i >= suffixes. len ( ) {
536+ // Rounding past the largest suffix leaves no suffix to promote to.
537+ let Some ( & suffix) = suffixes. get ( i) else {
540538 return Err ( translate ! ( "numfmt-error-number-too-big" ) ) ;
541- }
542- Ok ( ( v / bases[ 1 ] , Some ( ( suffixes [ i ] , with_i) ) ) )
539+ } ;
540+ Ok ( ( v / bases[ 1 ] , Some ( ( suffix , with_i) ) ) )
543541 } else {
544542 Ok ( ( v, Some ( ( suffixes[ i - 1 ] , with_i) ) ) )
545543 }
Original file line number Diff line number Diff line change @@ -100,11 +100,15 @@ fn test_to_si() {
100100}
101101
102102#[ test]
103- fn test_to_si_rounding_past_top_suffix_is_too_big ( ) {
103+ fn test_rounding_past_top_suffix ( ) {
104104 new_ucmd ! ( )
105105 . args ( & [ "--to=si" , "999500000000000000000000000000000" ] )
106106 . fails_with_code ( 2 )
107107 . stderr_only ( "numfmt: Number is too big and unsupported\n " ) ;
108+ new_ucmd ! ( )
109+ . args ( & [ "--to=iec" , "999500000000000000000000000000000" ] )
110+ . succeeds ( )
111+ . stdout_only ( "789Q\n " ) ;
108112}
109113
110114#[ test]
You can’t perform that action at this time.
0 commit comments