Skip to content

printf: floating point conversion flags not supported or incorrect #2774

@jfinkels

Description

@jfinkels

Floating point conversion flags are defined here: https://www.gnu.org/software/libc/manual/html_node/Floating_002dPoint-Conversions.html

Here are a few failing test cases:

Flag to always include a plus or minus sign:

$ printf "%+3.0f\n" 0
 +0
$ ./target/debug/coreutils printf "%+3.0f\n" 0
printf: %+: invalid conversion specification

Flag to pad the field with spaces:

$ printf "% 3.0f\n" 1
  1
$ ./target/debug/coreutils printf "% 3.0f\n" 1
printf: % : invalid conversion specification

Flag to pad the field with zeros instead of spaces:

$ printf "%03.0f\n" 0
000
$ ./target/debug/coreutils printf "%03.0f\n" 0
  0

Combining the + and 0 flags:

$ printf "%0+3.0f\n" 0
+00
$ ./target/debug/coreutils printf "%0+3.0f\n" 0
printf: %0+: invalid conversion specification

Combining the and - flags:

$ printf "% -3.0f\n" 1
 1
$ ./target/debug/coreutils printf "% -3.0f\n" 1
printf: % : invalid conversion specification

Discovered this while investigating #2616.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions