Skip to content

printf: negative numbers should wrap around when printed as unsigned/hexadecimal (%u/%x) #7488

@drinkcat

Description

@drinkcat

In GNU coreutils, negative numbers wrap around (64-bit integer), but uutils rejects them:

$ env printf "%x\n" -0b100; env printf "%x\n" -0100; env printf "%x\n" -100; env printf "%x\n" -0x100
fffffffffffffffc
ffffffffffffffc0
ffffffffffffff9c
ffffffffffffff00
$ cargo run printf "%x\n" -0b100; cargo run printf "%x\n" -100; cargo run printf "%x\n" -0x100
printf: '-0b100': expected a numeric value
0
printf: '-0100': expected a numeric value
0
printf: '-100': expected a numeric value
0
printf: '-0x100': expected a numeric value
0

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