File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -286,13 +286,22 @@ fn print_seq(
286286 let mut stdout = stdout. lock ( ) ;
287287 let ( first, increment, last) = range;
288288 let mut i = 0isize ;
289+ let is_first_minus_zero = first == -0.0 && first. is_sign_negative ( ) ;
289290 let mut value = first + i as f64 * increment;
291+ let mut is_first_iteration = true ;
290292 while !done_printing ( & value, & increment, & last) {
293+ let mut width = padding;
294+ if is_first_iteration && is_first_minus_zero {
295+ write ! ( stdout, "-" ) ;
296+ width -= 1 ;
297+ }
298+ is_first_iteration = false ;
299+
291300 let istr = format ! ( "{:.*}" , largest_dec, value) ;
292301 let ilen = istr. len ( ) ;
293302 let before_dec = istr. find ( '.' ) . unwrap_or ( ilen) ;
294- if pad && before_dec < padding {
295- for _ in 0 ..( padding - before_dec) {
303+ if pad && before_dec < width {
304+ for _ in 0 ..( width - before_dec) {
296305 write ! ( stdout, "0" ) ?;
297306 }
298307 }
Original file line number Diff line number Diff line change @@ -178,6 +178,15 @@ fn test_width_negative_zero() {
178178 . no_stderr ( ) ;
179179}
180180
181+ #[ test]
182+ fn test_width_negative_zero_scientific_notation ( ) {
183+ new_ucmd ! ( )
184+ . args ( & [ "-w" , "-0e0" , "1" ] )
185+ . succeeds ( )
186+ . stdout_is ( "-0\n 01\n " )
187+ . no_stderr ( ) ;
188+ }
189+
181190// TODO This is duplicated from `test_yes.rs`; refactor them.
182191/// Run `seq`, capture some of the output, close the pipe, and verify it.
183192fn run ( args : & [ & str ] , expected : & [ u8 ] ) {
You can’t perform that action at this time.
0 commit comments