php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41108 document when pow() and friends first allowed negative exponents
Submitted: 2007-04-17 01:37 UTC Modified: 2007-05-16 21:49 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jack dot nerad at comcast dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2007-04-17 01:37 UTC] jack dot nerad at comcast dot net
Description:
------------
It is a sin that PHP cannot handle negative exponents.  Every other respectable language that has half the vocabulary that PHP has can handle negative exponents.  Heck, even the windows calculator can handle negative exponents.  Please.  Mature and refine the language to include this ability. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-17 08:27 UTC] tony2001@php.net
What are you talking about?

# php -r 'var_dump(pow(2,-2));'
float(0.25)

 [2007-04-18 00:36 UTC] jack dot nerad at comcast dot net
Now that's turnaround time!  I didn't even have to upgrade to the latest version! :)

Actually, I was looking for how to do exponentiation in the docs, found pow(), and read:

"Note:  PHP cannot handle negative exps."

at

http://us.php.net/manual/en/function.pow.php

 
There's pretty much only one way to read that, I think, so I didn't bother to look for features explicitly ruled out by the docs.  In addition, there are a bunch of notes with hacks on how to get around the no negative exponents 'feature?'

(shrug) 

Close this feature request, or whatever. Maybe change it to a bug in the docs?
 [2007-04-18 06:09 UTC] derick@php.net
Made it a doc problem, which it is. It might be that in the past this negative exponent did not work though.
 [2007-04-18 20:23 UTC] ljbuesch at purdue dot edu
### Eclipse Workspace Patch 1.0
#P PHPDoc
Index: en/reference/math/functions/pow.xml
===================================================================
RCS file: /repository/phpdoc/en/reference/math/functions/pow.xml,v
retrieving revision 1.11
diff -u -r1.11 pow.xml
--- en/reference/math/functions/pow.xml	31 Mar 2007 19:18:23 -0000	1.11
+++ en/reference/math/functions/pow.xml	18 Apr 2007 20:18:37 -0000
@@ -16,11 +16,6 @@
    Returns <parameter>base</parameter> raised to the power of
    <parameter>exp</parameter>. 
   </para>
-  <note>
-   <para>
-    PHP cannot handle negative <parameter>exp</parameter>s.
-   </para>
-  </note>
   <warning>
    <para>
     In PHP 4.0.6 and earlier <function>pow</function> always returned
 [2007-04-18 21:32 UTC] philip@php.net
Thank you guys for the bug report and patch, it's the right idea but the php manual has change logs for functions.

Tasks for tackling this bug report:

- Find out exactly which PHP version(s) this behavior changed
- Add an entry to the changelog role in math/functions/pow.xml
- Add an example to these docs using a negative exponent, and 
  if appropriate add version info within the example comments
- Decide if other functions were affected by this change in the
  php sources (See also: NEWS, php-src/)
- If a 'fairly recent' change, add a nice example that works 
  in all versions
- Clean user notes

A good starting place:

- http://cvs.php.net/viewvc.cgi/php-src/ext/standard/math.c?view=log
- http://php.net/manual/en/function.pow

 [2007-04-18 21:46 UTC] tularis@php.net
Looks like php 4.2.0 introduced better pow() support (the whole function was re-done at revision 1.70 (just before 4.2.0rc1 release).
 [2007-04-19 02:25 UTC] ljbuesch at purdue dot edu
I apologize for not taking a better look at this documentation bug.  It appears that from bug#25751 was the first one to report that you cannot use negative bases in pow().

This is because it in the bug report, it would have resulted in a complex number, which PHP (at that time) did not support.  I am unsure if PHP supports complex numbers at this time.  In the bug report, it had shown a bogus result for the computation.  In the comments for math.c, version 1.69 it said that for PHP <=4.0.6 it would return bogus results for the Windows platform.  Since the bug report did not include a version number, I would assume that it was using that version. 

In bug#40729, it was shown that PHP can do negative bases in an example, and they assumed that it was a mistake made in the the pow() documentation, and that what they meant was that it couldn?t do negative exponents (an error in the fix for #25751).  The documentation was then changed to say it cannot handle negative powers.

I am not sure how you wanted the examples to be commented though, so I did what I thought was best.

### Eclipse Workspace Patch 1.0
#P PHPDoc
Index: en/reference/math/functions/pow.xml
===================================================================
RCS file: /repository/phpdoc/en/reference/math/functions/pow.xml,v
retrieving revision 1.11
diff -u -r1.11 pow.xml
--- en/reference/math/functions/pow.xml	31 Mar 2007 19:18:23 -0000	1.11
+++ en/reference/math/functions/pow.xml	19 Apr 2007 02:24:46 -0000
@@ -16,11 +16,6 @@
    Returns <parameter>base</parameter> raised to the power of
    <parameter>exp</parameter>. 
   </para>
-  <note>
-   <para>
-    PHP cannot handle negative <parameter>exp</parameter>s.
-   </para>
-  </note>
   <warning>
    <para>
     In PHP 4.0.6 and earlier <function>pow</function> always returned
@@ -76,7 +71,8 @@
        <entry>Since 4.0.6</entry>
        <entry>
         The function will now return <type>integer</type> results if possible,
-        before this it always returned a <type>float</type> result.
+        before this it always returned a <type>float</type> result.  For older
+		versions, you may receive a bogus result for complex numbers. 
        </entry>
       </row>
       <row>
@@ -104,8 +100,8 @@
 echo pow(-1, 20); // 1
 echo pow(0, 0); // 1
 
-echo pow(-1, 5.5); // error
-
+echo pow(-1, 5.5); // PHP >4.0.6  NAN
+echo pow(-1, 5.5); // PHP <=4.0.6 1.#IND
 ?>
 ]]>
     </programlisting>
 [2007-04-19 02:27 UTC] ljbuesch at purdue dot edu
Just a quick note on the Windows platform comment... it was commented in the previous bug report and not in the source comments.
 [2007-05-16 13:57 UTC] ljbuesch at purdue dot edu
As long as anyone isn't against the last patch, I will submit that patch later tonight and close this bug report.
 [2007-05-16 21:49 UTC] ljbuesch@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 11:01:33 2025 UTC