mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
seq: correct fixed-width spacing for inf sequences
Pad infinity and negative infinity values with spaces when using the `-w` option to `seq`. This corrects the behavior of `seq` to match that of the GNU version: $ seq -w 1.000 inf inf | head -n 4 1.000 inf inf inf Previously, it incorrectly padded with 0s instead of spaces.
This commit is contained in:
parent
2e12316ae1
commit
0b86afa858
2 changed files with 24 additions and 0 deletions
|
@ -235,6 +235,14 @@ fn write_value_float(
|
|||
width = if width > 0 { width - 1 } else { width },
|
||||
precision = precision,
|
||||
)
|
||||
} else if *value == ExtendedBigDecimal::Infinity || *value == ExtendedBigDecimal::MinusInfinity
|
||||
{
|
||||
format!(
|
||||
"{value:>width$.precision$}",
|
||||
value = value,
|
||||
width = width,
|
||||
precision = precision,
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{value:>0width$.precision$}",
|
||||
|
|
|
@ -530,6 +530,22 @@ fn test_inf() {
|
|||
run(&["inf"], b"1\n2\n3\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inf_width() {
|
||||
run(
|
||||
&["-w", "1.000", "inf", "inf"],
|
||||
b"1.000\n inf\n inf\n inf\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_neg_inf_width() {
|
||||
run(
|
||||
&["-w", "1.000", "-inf", "-inf"],
|
||||
b"1.000\n -inf\n -inf\n -inf\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_leading_whitespace() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue