Bug #67501 [Opn->Nab]: strange operation of comparison of same value

From: Date: Mon, 23 Jun 2014 17:26:35 +0000
Subject: Bug #67501 [Opn->Nab]: strange operation of comparison of same value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186306@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67501&edit=1 ID: 67501 Updated by: requinix@php.net Reported by: blazexerit at yahoo dot co dot jp Summary: strange operation of comparison of same value -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Linux PHP Version: 5.5.13 Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2014-06-23 11:15:02] blazexerit at yahoo dot co dot jp Description: ------------ after Test script php > var_dump($now,$next); int(1060) double(1060) php > if($now == $next) echo 1,PHP_EOL; else echo 0,PHP_EOL; 0 but, php > if((int)1060 == (double)1060) echo 1,PHP_EOL; else echo 0,PHP_EOL; 1 Test script: --------------- $r = 1060; $now = 0; $next = 0; $per = $r/50; $i=0; while($i!=$r){ $now++; while($now >= $next){ $next += $per; } $i++; } var_dump($now,$next); if($now == $next) echo 1,PHP_EOL; else echo 0,PHP_EOL; Expected result: ---------------- $now is 1060. $next is 1060. So, "if($now==$next)" will return true. Actual result: -------------- "if($now==$next)" returns false. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67501&edit=1

« previous php.bugs (#186306) next »