Bug #6019 Updated: document precision of floating point values

From: Date: Sun, 28 Apr 2002 22:16:57 +0000
Subject: Bug #6019 Updated: document precision of floating point values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-6367@lists.php.net to get a copy of this message
ID: 6019 Updated by: jimw@php.net -Summary: Error with equal operator when comparing certain values Reported By: thomas@netropolis.dk Status: Analyzed Bug Type: Feature/Change Request Operating System: NT4.0 PHP Version: 4.0.1pl2 New Comment: updating summary. Previous Comments: ------------------------------------------------------------------------ [2000-08-08 10:34:55] hholzgra@php.net the precisions are machine-/build-dependant so we can't document them in the manual maybe we can add a section to phpinfo() and/or some constants as in limits.h for MIN/MAX values for integer and float values (passed on to feature request) ------------------------------------------------------------------------ [2000-08-08 09:37:36] waldschrott@php.net I think this limitation isn´t mentioned anywhere clearly, transforming into docu bug In fact I don´t know where to look for it and I think the php.ini precision settings has nothing to do with it... ------------------------------------------------------------------------ [2000-08-08 09:25:26] waldschrott@php.net verified, replacing == with === in the third block will produce 0, what is correct for any reason the comparison is done corretly withing strings, I think you won´t have to switch to bcmaths functions for these tiny doubles, using var_dump() reveals that they´re correctly stored in $GLOABLS resumé: PHP performs return only 0,2,4 differences not 1,3,5 dealing with large numbers example: echo 9834567891230000-9834567891229999; // return2 s, should 1 echo 9834567891230000-9834567891230001; // returns 0, should -1 and so on ------------------------------------------------------------------------ [2000-08-08 09:07:23] stas@php.net 1. Use === when you are interested in string-to-string comparison. 2. PHP has precision limits, if you need more precision please use bc extension. ------------------------------------------------------------------------ [2000-08-08 08:59:54] thomas@netropolis.dk When comparing certain numbers using the equals operator (==) it returns true even though numbers are not equal. It doesnt matter if number is duoble or string. It only happens when number is 16 digit. 15 & 17 digits is OK. Using strcmp() doesnt produce this error. Example: <?php $one = 9834567891230000; //double $two = 9834567891230000; //double print(($one == $two)); //returns 1 (OK) $one = 9834567891230000; //double $two = 9834567891230001; //double print(($one == $two)); //returns 1 (wrong) $one = "9834567891230000"; //string $two = "9834567891230001"; //string print(($one == $two)); //returns 1 (wrong) $one = 9834567891230000; //double $two = 9834567891230002; //double print(($one == $two)); //returns 0 (OK) $one = 1834567891230000; //double $two = 1834567891230001; //double print(($one == $two)); //returns 0 (OK) ?> I have tried under diffrent versions of php both under linux and NT4.0 with the same result. latest: 4.0.1pl1 NT4.0 precompiled downloaded from php.net Can send php.ini if you want. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=6019&edit=1

« previous php.bugs (#6367) next »