GNU bug report logs - #54785
for floating point, printf should use double like in C instead of long double

Previous Next

Package: coreutils;

Reported by: Vincent Lefevre <vincent <at> vinc17.net>

Date: Fri, 8 Apr 2022 09:18:01 UTC

Severity: normal

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: bug-coreutils <at> gnu.org
Subject: for floating point, printf should use double like in C instead of
 long double
Date: Fri, 8 Apr 2022 11:17:19 +0200
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 <at> 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)




This bug report was last modified 3 years and 46 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.