Edit report at https://bugs.php.net/bug.php?id=60789&edit=1
ID: 60789 User updated by: ircmaxell at gmail dot com Reported by: ircmaxell at gmail dot com Summary: pow() uses floats if one argument is a float Status: Open -Type: Feature/Change Request +Type: Bug Package: Math related Operating System: *nix PHP Version: trunk-SVN-2012-01-18 (SVN) Block user comment: N Private report: N New Comment: Changing type to bug, as this fixes the implementation to correspond to the docs: http://us3.php.net/pow Specifically: "base raised to the power of exp. If the result can be represented as integer it will be returned as type integer, else it will be returned as type float." Previous Comments: ------------------------------------------------------------------------ [2012-01-18 13:00:30] ircmaxell at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=60789&edit=1