Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r58991:f4c2e0223550 Date: 2012-11-18 20:50 -0600 http://bitbucket.org/pypy/pypy/changeset/f4c2e0223550/
Log: merged upstream diff --git a/pypy/rpython/extfuncregistry.py b/pypy/rpython/extfuncregistry.py --- a/pypy/rpython/extfuncregistry.py +++ b/pypy/rpython/extfuncregistry.py @@ -42,6 +42,7 @@ ('sqrt', [float], float), ('log', [float], float), ('log10', [float], float), + ('log1p', [float], float), ('sin', [float], float), ('cos', [float], float), ('atan2', [float, float], float), 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 @@ -58,6 +58,7 @@ 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) @@ -363,6 +364,13 @@ 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") @@ -413,13 +421,13 @@ '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: diff --git a/pypy/rpython/lltypesystem/module/test/test_llinterp_math.py b/pypy/rpython/lltypesystem/module/test/test_llinterp_math.py --- a/pypy/rpython/lltypesystem/module/test/test_llinterp_math.py +++ b/pypy/rpython/lltypesystem/module/test/test_llinterp_math.py @@ -37,7 +37,7 @@ 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 @@ -82,3 +82,11 @@ 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit