Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r60071:92dd4a5d9a8f
Date: 2013-01-14 16:21 -0800
http://bitbucket.org/pypy/pypy/changeset/92dd4a5d9a8f/

Log:    pow(negative, fraction) now promotes to complex

diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -493,9 +493,11 @@
         if isnan(y):
             return W_FloatObject(NAN)
         if math.floor(y) != y:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("negative number cannot be "
-                                            "raised to a fractional power"))
+            # Negative numbers raised to fractional powers become
+            # complex
+            return space.pow(space.newcomplex(x, 0.0),
+                             space.newcomplex(y, 0.0),
+                             thirdArg)
         # y is an exact integer, albeit perhaps a very large one.
         # Replace x by its absolute value and remember to negate the
         # pow result if y is odd.
diff --git a/pypy/objspace/std/test/test_floatobject.py 
b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -242,6 +242,11 @@
             assert str(pw(float('-inf'), 1.0)) == '-inf'
             assert str(pw(float('-inf'), 2.0)) == 'inf'
 
+    def test_builtin_pow(self):
+        result = pow(-1, 0.5)
+        def assertAlmostEqual(x, y): assert round(abs(y - x), 7) == 0
+        assertAlmostEqual(result, 1j)
+
     def test_pow_neg_base(self):
         import math
         def pw(x, y):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to