Commits

Philip Jenvey committed 92dd4a5

pow(negative, fraction) now promotes to complex

  • Participants
  • Parent commits 0430488
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/objspace/std/floatobject.py

         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.

File pypy/objspace/std/test/test_floatobject.py

             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):