summaryrefslogtreecommitdiff
path: root/tests/run/cpow.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/cpow.pyx')
-rw-r--r--tests/run/cpow.pyx48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/run/cpow.pyx b/tests/run/cpow.pyx
index d2691ba6a..6f050337c 100644
--- a/tests/run/cpow.pyx
+++ b/tests/run/cpow.pyx
@@ -208,6 +208,54 @@ def pythagoras_with_typedef(double a, double b):
return result
+@cython.cpow(False)
+def power_coercion_in_nogil_1(double a, double b):
+ """
+ >>> power_coercion_in_nogil_1(2., 2.)
+ 4.0
+ >>> power_coercion_in_nogil_1(-1., 0.5)
+ Traceback (most recent call last):
+ ...
+ TypeError: Cannot convert 'complex' with non-zero imaginary component to 'double' (this most likely comes from the '**' operator; use 'cython.cpow(True)' to return 'nan' instead of a complex number).
+ """
+ cdef double c
+ with nogil:
+ c = a**b
+ return c
+
+
+cdef double nogil_fun(double x) nogil:
+ return x
+
+def power_coercion_in_nogil_2(double a, double b):
+ """
+ >>> power_coercion_in_nogil_2(2., 2.)
+ 4.0
+ >>> power_coercion_in_nogil_2(-1., 0.5)
+ Traceback (most recent call last):
+ ...
+ TypeError: Cannot convert 'complex' with non-zero imaginary component to 'double' (this most likely comes from the '**' operator; use 'cython.cpow(True)' to return 'nan' instead of a complex number).
+ """
+ c = a**b
+ with nogil:
+ d = nogil_fun(c)
+ return d
+
+
+def power_coercion_in_nogil_3(double a, double b, double c):
+ """
+ >>> power_coercion_in_nogil_3(2., 2., 1.0)
+ 0.25
+ >>> power_coercion_in_nogil_3(-1., 0.5, 1.0)
+ Traceback (most recent call last):
+ ...
+ TypeError: Cannot convert 'complex' with non-zero imaginary component to 'double' (this most likely comes from the '**' operator; use 'cython.cpow(True)' to return 'nan' instead of a complex number).
+ """
+ with nogil:
+ c /= a**b
+ return c
+
+
_WARNINGS = """
63:21: Treating '**' as if 'cython.cpow(True)' since it is directly assigned to a a non-complex C numeric type. This is likely to be fragile and we recommend setting 'cython.cpow' explicitly.
64:32: Treating '**' as if 'cython.cpow(True)' since it is directly assigned to a a non-complex C numeric type. This is likely to be fragile and we recommend setting 'cython.cpow' explicitly.