Alex Gaynor avatar Alex Gaynor committed f4c2e02 Merge

merged upstream

Comments (0)

Files changed (3)

pypy/rpython/extfuncregistry.py

        ('sqrt', [float], float),
        ('log', [float], float),
        ('log10', [float], float),
+       ('log1p', [float], float),
        ('sin', [float], float),
        ('cos', [float], float),
        ('atan2', [float, float], float),

pypy/rpython/lltypesystem/module/ll_math.py

 math_fabs = llexternal('fabs', [rffi.DOUBLE], rffi.DOUBLE)
 math_log = llexternal('log', [rffi.DOUBLE], rffi.DOUBLE)
 math_log10 = llexternal('log10', [rffi.DOUBLE], rffi.DOUBLE)
+math_log1p = llexternal('log1p', [rffi.DOUBLE], rffi.DOUBLE)
 math_copysign = llexternal(underscore + 'copysign',
                            [rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE,
                            elidable_function=True)
         raise ValueError("math domain error")
     return math_log10(x)
 
+def ll_math_log1p(x):
+    if x == 0.0:
+        return x      # returns 0.0 or -0.0
+    if x <= -1.0:
+        raise ValueError("math domain error")
+    return math_log1p(x)
+
 def ll_math_sin(x):
     if isinf(x):
         raise ValueError("math domain error")
     'acos', 'asin', 'atan',
     'ceil', 'cosh', 'exp', 'fabs',
     'sinh', 'tan', 'tanh',
-    'acosh', 'asinh', 'atanh', 'log1p', 'expm1',
+    'acosh', 'asinh', 'atanh', 'expm1',
     ]
 unary_math_functions_can_overflow = [
-    'cosh', 'exp', 'log1p', 'sinh', 'expm1',
+    'cosh', 'exp', 'sinh', 'expm1',
     ]
 unary_math_functions_c99 = [
-    'acosh', 'asinh', 'atanh', 'log1p', 'expm1',
+    'acosh', 'asinh', 'atanh', 'expm1',
     ]
 
 for name in unary_math_functions:

pypy/rpython/lltypesystem/module/test/test_llinterp_math.py

             assert self.interpret(f, [0.3, 0.4]) == f(0.3, 0.4)
         return next_test
 
-    for name in ll_math.unary_math_functions + ['log', 'log10', 'sin', 'cos', 'sqrt']:
+    for name in ll_math.unary_math_functions + ['log', 'log10', 'log1p', 'sin', 'cos', 'sqrt']:
         func_name = 'test_%s' % (name,)
         next_test = new_unary_test(name)
         next_test.func_name = func_name
                 return -42.0
 
         assert self.interpret(f, [10.0, 40000]) == -42.0
+
+    def test_log1p_zero(self):
+        def f(x):
+            x = rfloat.copysign(0.0, x)
+            return rfloat.copysign(1.0, rfloat.log1p(x))
+
+        assert self.interpret(f, [3.0]) == 1.0
+        assert self.interpret(f, [-2.0]) == -1.0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.