coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

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

Open drinkcat opened this issue 7 months ago • 0 comments

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

drinkcat avatar Mar 18 '25 20:03 drinkcat