-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
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.