From:             
Operating system: Linux Gentoo (2.6.38-gentoo-r6)
PHP version:      5.3.6
Package:          *Math Functions
Bug Type:         Bug
Bug description:ini_set('precision',16) is affecting a simple math result

Description:
------------
Hello,

The simple calculation does not result the same if we set the precision to
16. Maybe it's cpu architecture related ?

Precision lower than 16 :
(1.196 - 1) * 100 => 19.6
Precision 16 :
(1.196 - 1) * 100 => 19.59999999999999
Precision 17 :
(1.196 - 1) * 100 => 19.599999999999994
...

Here's the configure parameters :
'./configure' '--prefix=/usr' '--build=x86_64-pc-linux-gnu'
'--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man'
'--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc'
'--localstatedir=/var/lib' '--prefix=/usr/lib64/php5.3'
'--mandir=/usr/lib64/php5.3/man' '--infodir=/usr/lib64/php5.3/info'
'--libdir=/usr/lib64/php5.3/lib' '--with-libdir=lib64' '--without-pear'
'--disable-maintainer-zts' '--enable-bcmath' '--with-bz2'
'--enable-calendar' '--with-curl' '--with-curlwrappers' '--without-enchant'
'--enable-exif' '--enable-ftp' '--with-gettext' '--without-gmp'
'--without-mhash' '--disable-intl' '--without-kerberos' '--enable-mbstring'
'--with-mcrypt' '--without-mssql' '--with-onig=/usr' '--with-openssl'
'--with-openssl-dir=/usr' '--disable-pcntl' '--without-pgsql'
'--without-pspell' '--without-recode' '--disable-shmop' '--with-snmp'
'--disable-soap' '--enable-sockets' '--without-sqlite3'
'--without-sybase-ct' '--disable-sysvmsg' '--disable-sysvsem'
'--disable-sysvshm' '--with-tidy' '--disable-wddx' '--with-xmlrpc'
'--with-xsl' '--enable-zip' '--with-zlib' '--disable-debug' '--enable-dba'
'--without-cdb' '--with-db4' '--disable-flatfile' '--with-gdbm'
'--disable-inifile' '--without-qdbm' '--with-freetype-dir=/usr'
'--with-t1lib=/usr' '--disable-gd-jis-conv' '--with-jpeg-dir=/usr'
'--with-png-dir=/usr' '--without-xpm-dir' '--with-gd' '--with-imap'
'--with-imap-ssl' '--with-ldap' '--without-ldap-sasl' '--with-mysql=/usr'
'--with-mysql-sock=/var/run/mysqld/mysqld.sock'
'--with-mysqli=/usr/bin/mysql_config' '--with-unixODBC=/usr'
'--without-adabas' '--without-birdstep' '--without-dbmaker'
'--without-empress' '--without-esoob' '--without-ibm-db2' '--without-sapdb'
'--without-solid' '--with-iodbc=/usr' '--without-oci8'
'--with-oci8=instantclient,/usr/lib/oracle/10.2.0.3/client/lib'
'--without-pdo-dblib' '--with-pdo-mysql=/usr' '--without-pdo-pgsql'
'--without-pdo-sqlite' '--with-pdo-odbc=unixODBC,/usr'
'--with-pdo-oci=instantclient,/usr,10.2.0.3' '--with-readline'
'--without-libedit' '--without-mm' '--without-sqlite' '--with-pic'
'--with-pcre-regex=/usr' '--with-pcre-dir=/usr'
'--with-config-file-path=/etc/php/apache2-php5.3'
'--with-config-file-scan-dir=/etc/php/apache2-php5.3/ext-active'
'--disable-embed' '--disable-cli' '--disable-cgi' '--disable-fpm'
'--with-apxs2=/usr/sbin/apxs' 

Test script:
---------------
Interactive shell

php > var_dump(phpversion());
string(16) "5.3.6-pl0-gentoo"
php > var_dump((1.196-1)*100);
float(19.6)
php > var_dump(ini_get('precision'));
string(2) "14"
php > var_dump(ini_set('precision',14));
string(2) "14"
php > var_dump((1.196-1)*100);
float(19.6)
php > var_dump(ini_set('precision',15));
string(2) "14"
php > var_dump((1.196-1)*100);
float(19.6)
php > var_dump(ini_set('precision',16));
string(2) "15"
php > var_dump((1.196-1)*100);
float(19.59999999999999)
php > var_dump(ini_set('precision',17));
string(2) "16"
php > var_dump((1.196-1)*100);
float(19.599999999999994)
php > var_dump(ini_set('precision',18));
string(2) "17"
php > var_dump((1.196-1)*100);
float(19.5999999999999943)


Expected result:
----------------
I think the result must always be the same : (float)19.6

Actual result:
--------------
php > var_dump(ini_set('precision',16));
string(2) "15"
php > var_dump(("1.196"-1)*100);
float(19.59999999999999)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=55368&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55368&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55368&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55368&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55368&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55368&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55368&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55368&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55368&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55368&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55368&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55368&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55368&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55368&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55368&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55368&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55368&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55368&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55368&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55368&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55368&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55368&r=mysqlcfg

Reply via email to