[pypy-svn] r75820 - in pypy/branch/fast-forward/pypy/objspace/std: . test

benjamin at codespeak.net benjamin at codespeak.net
Sat Jul 3 17:02:59 CEST 2010


Author: benjamin
Date: Sat Jul  3 17:02:57 2010
New Revision: 75820

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
Log:
work around < 2.7's imperfect math.pow implementation

Modified: pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floatobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floatobject.py	Sat Jul  3 17:02:57 2010
@@ -1,4 +1,5 @@
-import operator, new
+import operator
+import sys
 from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std import model, newformat
@@ -442,6 +443,11 @@
                                                 "a negative power"))
         raise OperationError(space.w_ValueError,
                              space.wrap("float power"))
+    # Should the result be negated?
+    if (sys.version_info < (2, 7) and z == 0.0 and x < 0.0 and
+        not isinf(x) and not isinf(y) and
+        math.fmod(abs(y), 2.0) == 1.0):
+        z = -z
     return W_FloatObject(z)
 
 

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py	Sat Jul  3 17:02:57 2010
@@ -185,10 +185,14 @@
         assert pw(0.0, float("-inf")) == float("inf")
 
     def test_pow_neg_base(self):
+        import math
         def pw(x, y):
             return x ** y
         assert pw(-2.0, 2.0) == 4
-        
+        res = pw(-2.0, -2001.0)
+        assert res == -0.0
+        assert math.copysign(1., res) == -1.
+
     def test_float_cmp(self):
         assert 12.5 == 12.5
         assert 12.5 != -3.2



More information about the Pypy-commit mailing list