[php-maint] Bug#613982: printf generates scientific notation inaccurately
Ronan
mr_platelet+jin6vr at fastmail.fm
Fri Feb 18 17:03:08 UTC 2011
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
More information about the pkg-php-maint
mailing list