Tests for c division CEP 516
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 26 Mar 2009 01:58:53 +0000 (18:58 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 26 Mar 2009 01:58:53 +0000 (18:58 -0700)
tests/run/cdivision_CEP_516.pyx [new file with mode: 0644]

diff --git a/tests/run/cdivision_CEP_516.pyx b/tests/run/cdivision_CEP_516.pyx
new file mode 100644 (file)
index 0000000..ecb66a2
--- /dev/null
@@ -0,0 +1,52 @@
+__doc__ = u"""
+>>> v = [(17, 10), (-17, 10), (-17, -10), (17, -10)]
+>>> standard = [(a % b) for a, b in v]
+>>> standard
+[7, 3, -7, -3]
+>>> [mod_int_py(a, b) for a, b in v] == standard
+True
+>>> [mod_short_py(a, b) for a, b in v] == standard
+True
+>>> [mod_float_py(a, b) for a, b in v] == standard
+True
+>>> [mod_double_py(a, b) for a, b in v] == standard
+True
+
+>>> [mod_int_c(a, b) for a, b in v]
+[7, -7, -7, 7]
+>>> [mod_float_c(a, b) for a, b in v]
+[7.0, -7.0, -7.0, 7.0]
+>>> [mod_double_c(a, b) for a, b in v]
+[7.0, -7.0, -7.0, 7.0]
+"""
+
+cimport cython
+
+@cython.cdivision(False)
+def mod_int_py(int a, int b):
+    return a % b
+
+@cython.cdivision(False)
+def mod_short_py(short a, short b):
+    return a % b
+
+@cython.cdivision(False)
+def mod_double_py(double a, double b):
+    return a % b
+
+@cython.cdivision(False)
+def mod_float_py(float a, float b):
+    return a % b
+
+@cython.cdivision(True)
+def mod_int_c(int a, int b):
+    return a % b
+
+@cython.cdivision(True)
+def mod_float_c(float a, float b):
+    return a % b
+
+@cython.cdivision(True)
+def mod_double_c(double a, double b):
+    return a % b
+