From: Robert Bradshaw Date: Thu, 26 Mar 2009 01:58:53 +0000 (-0700) Subject: Tests for c division CEP 516 X-Git-Tag: 0.11.1.alpha~36 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4f8ba2bf447c3787dd5fe0d0ebc581156e72da80;p=cython.git Tests for c division CEP 516 --- diff --git a/tests/run/cdivision_CEP_516.pyx b/tests/run/cdivision_CEP_516.pyx new file mode 100644 index 00000000..ecb66a22 --- /dev/null +++ b/tests/run/cdivision_CEP_516.pyx @@ -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 +