|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60789 pow() uses floats if one argument is a float
Submitted: 2012-01-18 13:00 UTC Modified: 2012-03-04 19:12 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: ircmaxell at gmail dot com Assigned: cataphract (profile)
Status: Closed Package: Math related
PHP Version: trunk-SVN-2012-01-18 (SVN) OS: *nix
Private report: No CVE-ID: None
 [2012-01-18 13:00 UTC] ircmaxell at gmail dot com
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:

Actual result:


pow_float_to_int_cast.patch (last revision 2012-01-18 13:00 UTC by ircmaxell at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-18 15:09 UTC] ircmaxell at gmail dot com
Changing type to bug, as this fixes the implementation to correspond to the 


"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 15:09 UTC] ircmaxell at gmail dot com
-Type: Feature/Change Request +Type: Bug
 [2012-03-04 19:08 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed doc bug #60789: pow() uses floats if one argument is a float.
 [2012-03-04 19:12 UTC]
Fixed in SVN as a documentation bug.
 [2012-03-04 19:12 UTC]
-Status: Open +Status: Closed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cataphract
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 06:01:30 2024 UTC