Debian Bug report logs - #613982
printf generates scientific notation inaccurately

version graph

Package: php5-cli; Maintainer for php5-cli is (unknown);

Reported by: Ronan <mr_platelet+jin6vr@fastmail.fm>

Date: Fri, 18 Feb 2011 17:06:01 UTC

Severity: minor

Found in version php5/5.3.3-7

Fixed in version php5/5.3.5-1

Done: Raphael Geissert <geissert@debian.org>

Bug is archived. No further changes may be made.

Forwarded to http://bugs.php.net/47168

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#613982; Package php5-cli. (Fri, 18 Feb 2011 17:06:04 GMT) (full text, mbox, link).


Acknowledgement sent to Ronan <mr_platelet+jin6vr@fastmail.fm>:
New Bug report received and forwarded. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Fri, 18 Feb 2011 17:06:04 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Ronan <mr_platelet+jin6vr@fastmail.fm>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: printf generates scientific notation inaccurately
Date: Fri, 18 Feb 2011 17:03:08 +0000
Package: php5-cli
Version: 5.3.3-7
Severity: normal


printf, when outputting a number in scientific
notation, allows the precision to be specified.
However, the precision is capped at 40.  If a cap
has to be set at all, then it should be set at 52,
because this is the smallest value which allows all
IEEE double-precision floating-point numbers to be
output with perfect accuracy.

I've included a terminal transcript, in the file
sprintf-transcript, which shows a small PHP program
and its output.  The important point is that the
second number gives us 12 more bits of precision
than the first.

*** sprintf-transcript
Script started on Fri 18 Feb 2011 16:57:47 GMT
bash$ PS1='>>>>>>>>>>>> ' # make the prompt stand out more
>>>>>>>>>>>> cat demonstrate 
#!/usr/bin/php5 -n
<?php
error_reporting(-1);

/*
  PHP will emit a warning about truncating
  the precision to 40 digits
*/
printf("%.52e\n", 1 + pow(2, -52));

bcscale(52);
/*
  this scale is large enough to allow the
  calculation below to be performed without
  any loss of precision
*/

print bcadd(1, bcpow(2, -52)) . "\n";
>>>>>>>>>>>> php5 -n demonstrate 

Notice: printf(): Requested precision of 52 digits was truncated to PHP maximum of 40 digits in /home/ronan/work/php-bugs/sprintf/demonstrate on line 9
1.0000000000000002220446049250313080847263e+0
1.0000000000000002220446049250313080847263336181640625
>>>>>>>>>>>> exit

Script done on Fri 18 Feb 2011 16:58:00 GMT


-- System Information:
Debian Release: 6.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/1 CPU core)
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages php5-cli depends on:
ii  libbz2-1.0              1.0.5-6          high-quality block-sorting file co
ii  libc6                   2.11.2-10        Embedded GNU C Library: Shared lib
ii  libcomerr2              1.41.12-2        common error description library
ii  libdb4.8                4.8.30-2         Berkeley v4.8 Database Libraries [
ii  libgssapi-krb5-2        1.8.3+dfsg-4     MIT Kerberos runtime libraries - k
ii  libk5crypto3            1.8.3+dfsg-4     MIT Kerberos runtime libraries - C
ii  libkrb5-3               1.8.3+dfsg-4     MIT Kerberos runtime libraries
ii  libmagic1               5.04-5           File type determination library us
ii  libonig2                5.9.1-1          Oniguruma regular expressions libr
ii  libpcre3                8.02-1.1         Perl 5 Compatible Regular Expressi
ii  libqdbm14               1.8.77-4         QDBM Database Libraries [runtime]
ii  libssl0.9.8             0.9.8o-4squeeze1 SSL shared libraries
ii  libxml2                 2.7.8.dfsg-2     GNOME XML library
ii  mime-support            3.48-1           MIME files 'mime.types' & 'mailcap
ii  php5-common             5.3.3-7          Common files for packages built fr
ii  tzdata                  2010o-1          time zone and daylight-saving time
ii  ucf                     3.0025+nmu1      Update Configuration File: preserv
ii  zlib1g                  1:1.2.3.4.dfsg-3 compression library - runtime

php5-cli recommends no packages.

Versions of packages php5-cli suggests:
ii  php-pear                      5.3.3-7    PEAR - PHP Extension and Applicati

-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#613982; Package php5-cli. (Fri, 18 Feb 2011 20:36:02 GMT) (full text, mbox, link).


Acknowledgement sent to Raphael Geissert <geissert@debian.org>:
Extra info received and forwarded to list. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Fri, 18 Feb 2011 20:36:03 GMT) (full text, mbox, link).


Message #10 received at 613982@bugs.debian.org (full text, mbox, reply):

From: Raphael Geissert <geissert@debian.org>
To: Ronan <mr_platelet+jin6vr@fastmail.fm>, 613982@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: [php-maint] Bug#613982: printf generates scientific notation inaccurately
Date: Fri, 18 Feb 2011 14:32:41 -0600
severity 613982 minor
thanks

Hi,

On Friday 18 February 2011 11:03:08 Ronan wrote:
> printf, when outputting a number in scientific
> notation, allows the precision to be specified.
> However, the precision is capped at 40.  If a cap
> has to be set at all, then it should be set at 52,
> because this is the smallest value which allows all
> IEEE double-precision floating-point numbers to be
> output with perfect accuracy.

I don't know why a limit was set in place in the *printf functions, but 
according to the code that does the actual conversion it can handle a 
precision up to 318.

You can workaround it by using number_format btw (which internally uses the 
same formatter as *printf, without the arbitrary limit).

P.S. would be great if you could report it upstream. It would save us some 
time.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net




Severity set to 'minor' from 'normal' Request was from Raphael Geissert <geissert@debian.org> to control@bugs.debian.org. (Fri, 18 Feb 2011 20:36:04 GMT) (full text, mbox, link).


Information forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#613982; Package php5-cli. (Fri, 18 Feb 2011 21:57:08 GMT) (full text, mbox, link).


Acknowledgement sent to Ronan <mr_platelet+jin6vr@fastmail.fm>:
Extra info received and forwarded to list. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Fri, 18 Feb 2011 21:57:08 GMT) (full text, mbox, link).


Message #17 received at 613982@bugs.debian.org (full text, mbox, reply):

From: Ronan <mr_platelet+jin6vr@fastmail.fm>
To: Raphael Geissert <geissert@debian.org>
Cc: 613982@bugs.debian.org, control@bugs.debian.org
Subject: Re: [php-maint] Bug#613982: printf generates scientific notation inaccurately
Date: Fri, 18 Feb 2011 21:52:27 +0000
> P.S. would be great if you could report it upstream. It would save us some 
> time.

I compiled PHP 5.3.5, and found that the bug has actually been fixed
in that version.

Regards,

Ronan.




Information forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#613982; Package php5-cli. (Fri, 18 Feb 2011 23:12:03 GMT) (full text, mbox, link).


Acknowledgement sent to Raphael Geissert <geissert@debian.org>:
Extra info received and forwarded to list. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Fri, 18 Feb 2011 23:12:03 GMT) (full text, mbox, link).


Message #22 received at 613982@bugs.debian.org (full text, mbox, reply):

From: Raphael Geissert <geissert@debian.org>
To: Ronan <mr_platelet+jin6vr@fastmail.fm>, 613982@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: [php-maint] Bug#613982: Bug#613982: printf generates scientific notation inaccurately
Date: Fri, 18 Feb 2011 17:08:46 -0600
forwarded 613982 http://bugs.php.net/47168
fixed 613982 5.3.5-1
close 613982
thanks

On Friday 18 February 2011 15:52:27 Ronan wrote:
> > P.S. would be great if you could report it upstream. It would save us
> > some time.
> 
> I compiled PHP 5.3.5, and found that the bug has actually been fixed
> in that version.

Right, I knew I had seen a commit related to the printf precision not long 
ago.
5.3.5-1 was just accepted from the NEW queue, so I'm closing this report.

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net




Set Bug forwarded-to-address to 'http://bugs.php.net/47168'. Request was from Raphael Geissert <geissert@debian.org> to control@bugs.debian.org. (Fri, 18 Feb 2011 23:12:05 GMT) (full text, mbox, link).


Bug Marked as fixed in versions php5/5.3.5-1. Request was from Raphael Geissert <geissert@debian.org> to control@bugs.debian.org. (Fri, 18 Feb 2011 23:12:05 GMT) (full text, mbox, link).


Bug closed, send any further explanations to Ronan <mr_platelet+jin6vr@fastmail.fm> Request was from Raphael Geissert <geissert@debian.org> to control@bugs.debian.org. (Fri, 18 Feb 2011 23:12:06 GMT) (full text, mbox, link).


Information forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#613982; Package php5-cli. (Sun, 20 Feb 2011 17:51:03 GMT) (full text, mbox, link).


Acknowledgement sent to Ronan <mr_platelet+jin6vr@fastmail.fm>:
Extra info received and forwarded to list. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Sun, 20 Feb 2011 17:51:03 GMT) (full text, mbox, link).


Message #33 received at 613982@bugs.debian.org (full text, mbox, reply):

From: Ronan <mr_platelet+jin6vr@fastmail.fm>
To: 613982@bugs.debian.org
Subject: Bug#613982: Acknowledgement (printf generates scientific notation inaccurately)
Date: Sun, 20 Feb 2011 17:48:36 +0000
This message is probably of no interest to anyone
but myself.  Forgive me for sending it, but I want
to correct an error that I made.

I said that a precision of 52 decimal digits "allows
all IEEE double-precision floating-point numbers to
be output with perfect accuracy".  This is woefully
wrong; a counter-example is the number pow(2, -1024).




Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sun, 19 Jun 2011 07:36:09 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sun Jul 2 03:52:58 2023; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.