From: Operating system: Windows/Linux PHP version: 5.3.10 Package: Math related Bug Type: Bug Bug description:string math with vast differential numbers yield invalid math.
Description: ------------ Tried this on the latest 5.3.10 and also on 5.2.17 It is a bit difficult to put into words, but math with varying string-number sizes calculates wrong. Simply put: THIS IS CORRECT: ----------------- $x = 20.22 : double = 20.22 $y = ("10.10" + "10.12"); : double = 20.22 $x == $y : bool = TRUE THIS IS BUGGED: ------------------- $x = 20.22 : double = 20.22 $y = ("19.10" + "1.12"); //20.22 : double = 20.22 $x == $y : bool = FALSE For some reason, if you have a wide number spread in the string math, the boolean fails, even though they are both shown as float/double numbers The simple fix is to wrap round() around the string math. Can't really explain it. Test script: --------------- <?php $x = 23.36; $y = ("21.42" + "1.94"); if ($x < $y) { echo "math fail<br/>"; } else { echo "math win<br/>"; } var_dump($x, $y); echo "<br/>"; $x = 23.36; $y = ("10.36" + "13.00"); if ($x < $y) { echo "math fail<br/>"; } else { echo "math win<br/>"; } var_dump($x, $y); ?> Expected result: ---------------- I expect to see: math win float(23.36) float(23.36) math win float(23.36) float(23.36) Actual result: -------------- What I really see is: math fail float(23.36) float(23.36) math win float(23.36) float(23.36) -- Edit bug report at https://bugs.php.net/bug.php?id=61108&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61108&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61108&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61108&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61108&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61108&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61108&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61108&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61108&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61108&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61108&r=support Expected behavior: https://bugs.php.net/fix.php?id=61108&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61108&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61108&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61108&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61108&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61108&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61108&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61108&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61108&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61108&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61108&r=mysqlcfg