From: csaba at alum dot mit dot edu Operating system: Win XP PHP version: 5.2.5 PHP Bug Type: Math related Bug description: fmod($a,$b) wrong when $b is a multiple of $a - continued
Description: ------------ This continues bug report 43572 at http://bugs.php.net/bug.php?id=43572&edit=2 which discussion is incomplete, yet has been prematurely closed. > The value that you expect (0) is obtained using float precision. > (In C) PHP uses double, and with this type fmod() returns 1.3. So, to be concrete: $a = 6.5; print gettype($a); // double $b = 1.3; print gettype($b); // double $c = $a / $b; print gettype($c); // double $d = 5.0; print gettype ($d); // double print $c - $d; // 0 print (gettype($c - $d)); // double print ($c===$d) ? "same" : "different"; // same print gettype ($b - fmod($a, $b)); // double print $b - fmod($a, $b); // 2.22044604925E-16 In other words, PHP's own (double) math shows that 6.5 / 1.3 === 5.0 Regardless of the internal representation and precision of 6.5 and 1.3, division of the former ($a) by the latter ($b) results in a double value identical to 5.0. fMod should return 0 in this situation. Csaba Gabor from New York PS. I would prefer that these comments be moved to bug 43572 and that it be reopened until the discussion is completed, rather than having multiple threads. -- Edit bug report at http://bugs.php.net/?id=43624&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43624&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43624&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43624&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43624&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43624&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43624&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43624&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43624&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43624&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43624&r=support Expected behavior: http://bugs.php.net/fix.php?id=43624&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43624&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43624&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43624&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43624&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43624&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43624&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43624&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43624&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43624&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43624&r=mysqlcfg