Bug->Doc #60789 [Opn->Csd]: pow() uses floats if one argument is a float
| From: | cataphract@php.net | Date: | Sun, 04 Mar 2012 19:12:31 +0000 |
| Subject: | Bug->Doc #60789 [Opn->Csd]: pow() uses floats if one argument is a float | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8022@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60789&edit=1
ID: 60789
Updated by: cataphract@php.net
Reported by: ircmaxell at gmail dot com
Summary: pow() uses floats if one argument is a float
-Status: Open
+Status: Closed
-Type: Bug
+Type: Documentation Problem
Package: Math related
Operating System: *nix
PHP Version: trunk-SVN-2012-01-18 (SVN)
-Assigned To:
+Assigned To: cataphract
Block user comment: N
Private report: N
New Comment:
Fixed in SVN as a documentation bug.
Previous Comments:
------------------------------------------------------------------------
[2012-03-04 19:08:11] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=323895
Log: - Fixed doc bug #60789: pow() uses floats if one argument is a float.
------------------------------------------------------------------------
[2012-01-18 15:09:23] ircmaxell at gmail dot com
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."
------------------------------------------------------------------------
[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