Bug #63136 [Opn]: pow() returns NaN where base is negative and exponent is an odd number root
| From: | tstobbe at sacbee dot com | Date: | Sat, 22 Sep 2012 02:47:21 +0000 |
| Subject: | Bug #63136 [Opn]: pow() returns NaN where base is negative and exponent is an odd number root | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173623@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63136&edit=1
ID: 63136
User updated by: tstobbe at sacbee dot com
Reported by: tstobbe at sacbee dot com
Summary: pow() returns NaN where base is negative and
exponent is an odd number root
Status: Open
Type: Bug
Package: Math related
Operating System: Linux (fc17, 32-bit)
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
It should be noted that all subsequent fractional pow() issues are related to this. For example:
pow(-[any number], 1/5) vs pow(-[any number], 2/5). Likewise I suspect that most other exponent
based functions (such as log with an arbitrary base) are probably suspect, but this hasn't been
verified.
Previous Comments:
------------------------------------------------------------------------
[2012-09-21 22:38:15] tstobbe at sacbee dot com
Description:
------------
Odd roots (3, 5, etc) of negative numbers passed to pow() result in NaN rather
than the actual result. While this makes sense for even numbered roots (sqrt and
what-not), it wrecks havoc on any system that actually uses arbitrary roots of
negative numbers.
Example: -2*-2*-2 = -8; pow(-8, 1/3) should return -2
Test script:
---------------
var_dump(pow(-8, 1/3));
Expected result:
----------------
float(-2)
Actual result:
--------------
float(NAN)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63136&edit=1