From: Operating system: *nix PHP version: trunk-SVN-2012-01-18 (SVN) Package: Math related Bug Type: Feature/Change Request Bug description:pow() uses floats if one argument is a float
Description: ------------ I ran into an issue with pow() that causes it to lose precision on 64 bit platforms if one or more of the arguments is a float. I've attached a patch that fixes this by checking if both arguments are exactly representable as an integer, and if so converting to an integer. This attempts to retain as much precision as possible by letting the result be an exact representation where possible. Additionally, the patch fixes a tested-for-bug on 64 bit platforms where: pow(-9.2233720368548E+18, 9223372036854775807) == INF when it should be -INF. Test script: --------------- var_dump((int) (pow(2, (float) 55) - 1)); Expected result: ---------------- int(36028797018963967) Actual result: -------------- int(36028797018963968) -- Edit bug report at https://bugs.php.net/bug.php?id=60789&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60789&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60789&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60789&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60789&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60789&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60789&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60789&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60789&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60789&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60789&r=support Expected behavior: https://bugs.php.net/fix.php?id=60789&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60789&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60789&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60789&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60789&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60789&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60789&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60789&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60789&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60789&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60789&r=mysqlcfg