[pypy-commit] pypy default: prefer OverflowError for log{, 10, 1p} math edge cases

mattip noreply at buildbot.pypy.org
Thu Dec 13 23:09:55 CET 2012


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r59411:47d8c17d7a49
Date: 2012-12-13 14:09 -0800
http://bitbucket.org/pypy/pypy/changeset/47d8c17d7a49/

Log:	prefer OverflowError for log{,10,1p} math edge cases

diff --git a/pypy/module/math/test/test_direct.py b/pypy/module/math/test/test_direct.py
--- a/pypy/module/math/test/test_direct.py
+++ b/pypy/module/math/test/test_direct.py
@@ -72,9 +72,10 @@
         ('exp', (9999.9,), OverflowError),
         ('pow', (10.0, 40000.0), OverflowError),
         ('ldexp', (10.0, 40000), OverflowError),
-        ('log', (0.0,), ValueError),
+        ('log', (0.0,), OverflowError),
+        ('log1p', (-1.0,), OverflowError),
         ('log', (-1.,), ValueError),
-        ('log10', (0.0,), ValueError),
+        ('log10', (0.0,), OverflowError),
         ]
 
     INFCASES = [
diff --git a/pypy/rpython/lltypesystem/module/ll_math.py b/pypy/rpython/lltypesystem/module/ll_math.py
--- a/pypy/rpython/lltypesystem/module/ll_math.py
+++ b/pypy/rpython/lltypesystem/module/ll_math.py
@@ -356,11 +356,15 @@
 
 def ll_math_log(x):
     if x <= 0:
+        if x == 0:
+            raise OverflowError("math range  error")
         raise ValueError("math domain error")
     return math_log(x)
 
 def ll_math_log10(x):
     if x <= 0:
+        if x == 0:
+            raise OverflowError("math range  error")
         raise ValueError("math domain error")
     return math_log10(x)
 
@@ -368,6 +372,8 @@
     if x == 0.0:
         return x      # returns 0.0 or -0.0
     if x <= -1.0:
+        if x == -1:
+            raise OverflowError("math range  error")
         raise ValueError("math domain error")
     return math_log1p(x)
 


More information about the pypy-commit mailing list