[pypy-svn] r72274 - pypy/branch/ll_math/pypy/rpython/lltypesystem/module

arigo at codespeak.net arigo at codespeak.net
Tue Mar 16 12:45:38 CET 2010


Author: arigo
Date: Tue Mar 16 12:45:37 2010
New Revision: 72274

Modified:
   pypy/branch/ll_math/pypy/rpython/lltypesystem/module/ll_math.py
Log:
Added fmod.


Modified: pypy/branch/ll_math/pypy/rpython/lltypesystem/module/ll_math.py
==============================================================================
--- pypy/branch/ll_math/pypy/rpython/lltypesystem/module/ll_math.py	(original)
+++ pypy/branch/ll_math/pypy/rpython/lltypesystem/module/ll_math.py	Tue Mar 16 12:45:37 2010
@@ -163,6 +163,25 @@
     return math_copysign(x, y)     # no error checking needed
 
 
+def ll_math_fmod(x, y):
+    if isinf(y):
+        if isinf(x):
+            raise ValueError("math domain error")
+        return x  # fmod(x, +/-Inf) returns x for finite x (or if x is a NaN).
+
+    _error_reset()
+    r = math_fmod(x, y)
+    errno = rposix.get_errno()
+    if isnan(r):
+        if isnan(x) or isnan(y):
+            errno = 0
+        else:
+            errno = EDOM
+    if errno:
+        _likely_raise(errno, r)
+    return r
+
+
 def ll_math_hypot(x, y):
     # hypot(x, +/-Inf) returns Inf, even if x is a NaN.
     if isinf(x):
@@ -278,9 +297,10 @@
 # ____________________________________________________________
 
 unary_math_functions = [
-    'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh',
+    'acos', 'asin', 'atan',
     'ceil', 'cos', 'cosh', 'exp', 'fabs', 'floor',
-    'log1p', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
+    'sin', 'sinh', 'sqrt', 'tan', 'tanh',
+    # 'log1p', 'acosh', 'asinh', 'atanh',   -- added in Python 2.6
     ]
 unary_math_functions_can_overflow = [
     'cosh', 'exp', 'log1p', 'sinh', # why log1p? CPython does it



More information about the Pypy-commit mailing list