[pypy-svn] r75949 - in pypy/branch/fast-forward/pypy: module/math module/math/test rlib rpython/lltypesystem/module

benjamin at codespeak.net benjamin at codespeak.net
Wed Jul 7 01:56:22 CEST 2010


Author: benjamin
Date: Wed Jul  7 01:56:20 2010
New Revision: 75949

Modified:
   pypy/branch/fast-forward/pypy/module/math/__init__.py
   pypy/branch/fast-forward/pypy/module/math/interp_math.py
   pypy/branch/fast-forward/pypy/module/math/test/test_math.py
   pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
   pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py
Log:
add math.expm1

Modified: pypy/branch/fast-forward/pypy/module/math/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/__init__.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/__init__.py	Wed Jul  7 01:56:20 2010
@@ -44,5 +44,6 @@
        'acosh'          : 'interp_math.acosh',
        'atanh'          : 'interp_math.atanh',
        'log1p'          : 'interp_math.log1p',
+       'expm1'          : 'interp_math.expm1',
 }
 

Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py	Wed Jul  7 01:56:20 2010
@@ -416,3 +416,8 @@
     """Inverse hyperbolic tangent"""
     return math1(space, rarithmetic.atanh, x)
 atanh.unwrap_spec = [ObjSpace, float]
+
+def expm1(space, x):
+    """exp(x) - 1"""
+    return math1(space, rarithmetic.expm1, x)
+expm1.unwrap_spec = [ObjSpace, float]

Modified: pypy/branch/fast-forward/pypy/module/math/test/test_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/test/test_math.py	(original)
+++ pypy/branch/fast-forward/pypy/module/math/test/test_math.py	Wed Jul  7 01:56:20 2010
@@ -123,6 +123,7 @@
         import math
         import abc
         import os
+        import struct
         def _parse_mtestfile(fname):
             """Parse a file with test values
 

Modified: pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rarithmetic.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rarithmetic.py	Wed Jul  7 01:56:20 2010
@@ -132,6 +132,17 @@
         else:
             return math.log(1. + x)
 
+try:
+    from math import expm1 # Added in Python 2.7.
+except ImportError:
+    def expm1(x):
+        if abs(x) < .7:
+            u = math.exp(x)
+            if u == 1.:
+                return x
+            return (u - 1.) * x / math.log(u)
+        return math.exp(x) - 1.
+
 def intmask(n):
     if isinstance(n, int):
         return int(n)   # possibly bool->int

Modified: pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py	(original)
+++ pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py	Wed Jul  7 01:56:20 2010
@@ -319,7 +319,7 @@
     'acosh', 'asinh', 'atanh',   # -- added in Python 2.6
     ]
 unary_math_functions_can_overflow = [
-    'cosh', 'exp', 'log1p', 'sinh',
+    'cosh', 'exp', 'log1p', 'sinh', 'expm1',
     ]
 
 for name in unary_math_functions:



More information about the Pypy-commit mailing list