This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pdenis
Recipients pdenis
Date 2017-11-29.21:29:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511990992.11.0.213398074469.issue32171@psf.upfronthosting.co.za>
In-reply-to
Content
Python returns inconsistent results when negative infinity is raised to a non-integer power. This happens with the ** operator as well as with the pow and math.pow functions. The most blatant symptom occurs with power 0.5, which is expectedly equivalent to a square root:

>>> float('-inf') ** 0.5
inf
>>> pow(float('-inf'), 0.5)
inf
>>> import math
>>> math.pow(float('-inf'), 0.5)
inf

Mathematically, these operations are invalid if we restrict to real numbers. Also, if we extend to complex numbers, the results are wrong since the result should be infj, which is the value returned by cmath.sqrt(float('-inf')).

IMHO, there are three possible ways to fix this:

1) raise an exception ValueError
2) return nan
3) return (nan + nanj)

Discussion:

- Solution 1) is consistent with current handling of *finite* negative base with non-integer exponent; also, it is consistent with math.sqrt(float('-inf')), which raises ValueError.

- I expected solution 2) to be more in line with IEEE754 … until I read the following statement in this specification: "pow(x, y) signals the invalid operation exception for finite x<0 and finite non-integer y". I’m not an expert of this topic but I think that there is miss here since IEEE754 does not state what happens for *infinite* x<0 and finite non-integer y.

- Solution 3) emphasizes the fact that, although the result is generally undefined, it belongs to complex type.

- In any case, the solution should be consistent also with the case with negative fractional exponent… even if I would tend to accept that (float('-inf')**-0.5) == 0.0 is mathematically sensible!

- The test assertions shall be updated in Python standard test suite (test_float.py).

Note that Python 2.6 behaves consistently for all negative bases, finite or not finite: it raises ValueError exception with the message "negative number cannot be raised to a fractional power". The behavior described here seems to be introduced in this commit: https://github.com/python/cpython/commit/9ab44b509a935011beb8e9108a2271ee728e8ad4#diff-b7e3652f51768cec742ef07326413ad0
History
Date User Action Args
2017-11-29 21:29:52pdenissetrecipients: + pdenis
2017-11-29 21:29:52pdenissetmessageid: <1511990992.11.0.213398074469.issue32171@psf.upfronthosting.co.za>
2017-11-29 21:29:52pdenislinkissue32171 messages
2017-11-29 21:29:51pdeniscreate