[pypy-svn] r77077 - in pypy/branch/fast-forward/pypy: rpython/lltypesystem/module rpython/lltypesystem/module/test translator/c/src
afa at codespeak.net
afa at codespeak.net
Wed Sep 15 10:13:20 CEST 2010
Author: afa
Date: Wed Sep 15 10:13:18 2010
New Revision: 77077
Modified:
pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py
pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/test/test_ll_math.py
pypy/branch/fast-forward/pypy/translator/c/src/math.c
Log:
Implement math.isnan and math.isinf for Windows
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 Sep 15 10:13:18 2010
@@ -18,16 +18,25 @@
separate_module_files=[srcdir.join('math.c')],
export_symbols=['_pypy_math_acosh', '_pypy_math_asinh',
'_pypy_math_atanh',
- '_pypy_math_expm1', '_pypy_math_log1p'],
+ '_pypy_math_expm1', '_pypy_math_log1p',
+ '_pypy_math_isinf', '_pypy_math_isnan'],
)
+ math_prefix = '_pypy_math_'
else:
eci = ExternalCompilationInfo(
libraries=['m'])
+ math_eci = eci
+ math_prefix = ''
def llexternal(name, ARGS, RESULT):
return rffi.llexternal(name, ARGS, RESULT, compilation_info=eci,
sandboxsafe=True)
+def math_llexternal(name, ARGS, RESULT):
+ return rffi.llexternal(math_prefix + name, ARGS, RESULT,
+ compilation_info=math_eci,
+ sandboxsafe=True)
+
if sys.platform == 'win32':
underscore = '_'
else:
@@ -46,8 +55,8 @@
math_fmod = llexternal('fmod', [rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE)
math_hypot = llexternal(underscore + 'hypot',
[rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE)
-math_isinf = llexternal('isinf', [rffi.DOUBLE], rffi.INT)
-math_isnan = llexternal('isnan', [rffi.DOUBLE], rffi.INT)
+math_isinf = math_llexternal('isinf', [rffi.DOUBLE], rffi.INT)
+math_isnan = math_llexternal('isnan', [rffi.DOUBLE], rffi.INT)
# ____________________________________________________________
#
@@ -296,9 +305,7 @@
def new_unary_math_function(name, can_overflow, c99):
if sys.platform == 'win32' and c99:
- win32name = '_pypy_math_%s' % (name,)
- c_func = rffi.llexternal(win32name, [rffi.DOUBLE], rffi.DOUBLE,
- compilation_info=math_eci, sandboxsafe=True)
+ c_func = math_llexternal(name, [rffi.DOUBLE], rffi.DOUBLE)
else:
c_func = llexternal(name, [rffi.DOUBLE], rffi.DOUBLE)
Modified: pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/test/test_ll_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/test/test_ll_math.py (original)
+++ pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/test/test_ll_math.py Wed Sep 15 10:13:18 2010
@@ -6,7 +6,19 @@
class TestMath(MathTests):
- pass
+ def test_isinf(self):
+ inf = 1e200 * 1e200
+ nan = inf / inf
+ assert not ll_math.ll_math_isinf(0)
+ assert ll_math.ll_math_isinf(inf)
+ assert not ll_math.ll_math_isinf(nan)
+
+ def test_isnan(self):
+ inf = 1e200 * 1e200
+ nan = inf / inf
+ assert not ll_math.ll_math_isnan(0)
+ assert ll_math.ll_math_isnan(nan)
+ assert not ll_math.ll_math_isnan(inf)
def make_test_case((fnname, args, expected), dict):
#
Modified: pypy/branch/fast-forward/pypy/translator/c/src/math.c
==============================================================================
--- pypy/branch/fast-forward/pypy/translator/c/src/math.c (original)
+++ pypy/branch/fast-forward/pypy/translator/c/src/math.c Wed Sep 15 10:13:18 2010
@@ -18,6 +18,18 @@
#undef PyPy_NAN
+int
+_pypy_math_isinf(double x)
+{
+ return PyPy_IS_INFINITY(x);
+}
+
+int
+_pypy_math_isnan(double x)
+{
+ return PyPy_IS_NAN(x);
+}
+
/* The following copyright notice applies to the original
implementations of acosh, asinh and atanh. */
More information about the Pypy-commit
mailing list