[pypy-svn] r16934 - in pypy/dist/pypy/objspace/std: . test

pedronis at codespeak.net pedronis at codespeak.net
Sun Aug 28 10:49:16 CEST 2005


Author: pedronis
Date: Sun Aug 28 10:49:15 2005
New Revision: 16934

Modified:
   pypy/dist/pypy/objspace/std/longobject.py
   pypy/dist/pypy/objspace/std/test/test_longobject.py
Log:
try to mimic better CPython behavior with math.log(negative long or zero long)



Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/longobject.py	Sun Aug 28 10:49:15 2005
@@ -1293,6 +1293,8 @@
     small enough to fit in an IEEE single.  log and log10 are even smaller.
     """
     x, e = _AsScaledDouble(w_arg);
+    if x <= 0.0:
+        raise ValueError
     # Value is ~= x * 2**(e*SHIFT), so the log ~=
     # log(x) + log(2) * e * SHIFT.
     # CAUTION:  e*SHIFT may overflow using int arithmetic,

Modified: pypy/dist/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_longobject.py	Sun Aug 28 10:49:15 2005
@@ -395,3 +395,13 @@
         assert hash(123456789L) == 123456789
         assert hash(1234567890123456789L) == -1895067127
         assert hash(-3**333) == -368329968
+
+    def math_log(self):
+        import math
+        raises(ValueError, math.log, 0L) 
+        raises(ValueError, math.log, -1L) 
+        raises(ValueError, math.log, -2L) 
+        raises(ValueError, math.log, -(1L << 10000))
+        raises(ValueError, math.log, 0) 
+        raises(ValueError, math.log, -1) 
+        raises(ValueError, math.log, -2) 



More information about the Pypy-commit mailing list