Bug #79370 [Opn->Nab]: Comparison problem

From: Date: Thu, 12 Mar 2020 09:16:28 +0000
Subject: Bug #79370 [Opn->Nab]: Comparison problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226048@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79370&edit=1 ID: 79370 Updated by: nikic@php.net Reported by: danil at pyatnitsev dot ru Summary: Comparison problem -Status: Open +Status: Not a bug Type: Bug Package: Variables related Operating System: Debian PHP Version: 7.4.3 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: ------------------------------------------------------------------------ [2020-03-12 09:13:50] danil at pyatnitsev dot ru Description: ------------ Incorrect comparison after addition float with integer Test script: --------------- <?php $foo = (float) 32.77; $bar = (float) 31.77; $bar += 1; var_dump($foo == $bar); // false var_dump($foo, $bar); // float(32.77) float(32.77) Expected result: ---------------- var_dump($foo == $bar); should be true in this case Actual result: -------------- It prints false ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79370&edit=1

« previous php.bugs (#226048) next »