Skip to content

printf: Parsing large numbers outside of type range should return saturated value wrapped in the error #7508

@drinkcat

Description

@drinkcat

When parsing very large numbers into i64, we should return an error, but also wrap INT64_MIN/MAX value in the error so that value gets printed:

$ env printf '%d\n' -92233720368547758080
printf: ‘-92233720368547758080’: Numerical result out of range
-9223372036854775808
$ env printf '%d\n' 92233720368547758080
printf: ‘92233720368547758080’: Numerical result out of range
9223372036854775807
$ ./coreutils-main printf '%d\n' -92233720368547758080
printf: '-92233720368547758080': Numerical result out of range
0
$ ./coreutils-main printf '%d\n' 92233720368547758080
printf: '92233720368547758080': Numerical result out of range
0

Similarly with u64, the value returned is UINT64_MAX:

$ env printf '%u\n' 92233720368547758080
printf: ‘92233720368547758080’: Numerical result out of range
18446744073709551615
$ ./coreutils-main printf '%u\n' 92233720368547758080
printf: '92233720368547758080': Numerical result out of range
0

And again with f64 (ExtendedBigDecimal can also hit this as it is limited to 64-bit exponent . -- Note that scientific format is not supported by printf yet, #7474), where underflow returns 0 and overflow returns inf:

$ env printf '%f\n' 1e-92233720368547758080
printf: ‘1e-92233720368547758080’: Numerical result out of range
0.000000
env printf '%f\n' 1e92233720368547758080
printf: ‘1e92233720368547758080’: Numerical result out of range
inf

This float case also matters for seq, which does this correctly already, but I'm trying to merge the parsing functions.

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