php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66288 pow() gives unexpected results if exponent is negative
Submitted: 2013-12-13 16:11 UTC Modified: 2013-12-14 00:20 UTC
From: mattT1227 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.7 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mattT1227 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-12-13 16:11 UTC] mattT1227 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.pow
---
At least show example that negative exponents are not correctly implemented by pow.

Note, reporting system shows this problem has been suspended. It is still a problem. 

Test script:
---------------
echo pow(4, -2); // should be same as square root of 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-13 18:24 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2013-12-13 18:24 UTC] aharvey@php.net
pow() handles negative exponents fine: pow(4, -2) is 0.0625, which seems correct to me and also to Wolfram|Alpha: http://www.wolframalpha.com/input/?i=4^-2

Closing not a bug.
 [2013-12-13 22:15 UTC] rasmus@php.net
By the way, where is the suspended bug on this? We should mark that as Not-a-bug as well. 4^-2 is the same as 1/(4^2) which is most definitely not the same as the square root of 4. Where in the world did you get that from?
 [2013-12-14 00:20 UTC] datibbaw@php.net
The square root of 4 is calculated with a power of 1/2, i.e.

pow(4, 0.5) == float(2)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 01:01:32 2024 UTC