bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54785: for floating point, printf should use double like in C instea


From: Vincent Lefevre
Subject: bug#54785: for floating point, printf should use double like in C instead of long double
Date: Fri, 8 Apr 2022 11:17:19 +0200
User-agent: Mutt/2.2.2+9 (f082dd14) vl-138565 (2022-03-25)

The printf command assumes that floating-point arguments are long double
values, which can yield surprising results, while most of the time the
double type is assumed by applications (for instance, this is the case
of XPath).

For instance:

$ zsh -fc '/usr/bin/printf "%a\n" $((43./2**22))'
0xa.c0000000000025cp-20

instead of

0xa.cp-20

(Note that ksh uses long double internally, but does not ensure the
round trip back to long double, so that this is incorrect anyway; see
https://unix.stackexchange.com/questions/422122/why-does-0-1-expand-to-0-10000000000000001-in-zsh
by Stephane Chazelas.)

I suppose that the issue is at the parsing level (after parsing the
value as a double, i.e. rounding to a double, the resulting binary
value can internally be stored either in a double or a long double
without changing its value).

I suggest to parse the argument as a "long double" only if the "L"
length modifier is provided, like in C.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]