[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug#54785: for floating point, printf should use double like in C in
From: |
Chet Ramey |
Subject: |
Re: bug#54785: for floating point, printf should use double like in C instead of long double |
Date: |
Mon, 11 Apr 2022 14:52:50 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 |
On 4/9/22 3:31 PM, Paul Eggert wrote:
I suggest to parse the argument as a "long double" only if the "L"
length modifier is provided, like in C.
Thanks, good idea.
I checked, and this also appears to be a POSIX conformance issue. POSIX
says that floating point operands "shall be evaluated as if by the
strtod() function". This means double, not long double.
Whatever decision we make here, we should be consistent with Bash so I'll
cc this email to bug-bash.
I propose that we change both coreutils and Bash to use 'double' rather
than 'long double' here, unless the user specifies the L modifier (e.g.,
"printf '%La\n' ...". I've written up a patch (attached) to Bash 5.2 alpha
to do that. Assuming the Bash maintainer likes this proposal, I plan to
implement something similar for Coreutils printf.
It sounds like there are three cases.
1. If the `L' modifier is supplied, as an extension (POSIX doesn't allow
length modifiers for the printf utility), use long double. This would
work in both default and posix modes.
2. In posix mode, use strtod() and double.
3. In default mode, use the existing code to get the highest possible
precision, as the code has done for over 20 years.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Paul Eggert, 2022/04/09
- Re: bug#54785: for floating point, printf should use double like in C instead of long double,
Chet Ramey <=
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Vincent Lefevre, 2022/04/11
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Paul Eggert, 2022/04/25
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Chet Ramey, 2022/04/25
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Paul Eggert, 2022/04/25
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Chet Ramey, 2022/04/29
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Paul Eggert, 2022/04/29
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Vincent Lefevre, 2022/04/30
- Re: bug#54785: for floating point, printf should use double like in C instead of long double, Paul Eggert, 2022/04/30