ID: 6019 Updated by: [EMAIL PROTECTED] -Summary: Error with equal operator when comparing certain values Reported By: [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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