Commit 6e54e1e6 authored by Robert Bradshaw's avatar Robert Bradshaw

int powering tests

parent 64724e68
def f(): def f():
cdef char *str1 cdef char *str1
cdef float flt1, flt2, flt3 cdef float flt1, flt2, flt3
cdef int int1 = 1, int2 = 2, int3
flt1 = str1 ** flt3 # error flt1 = str1 ** flt3 # error
flt1 = flt2 ** str1 # error flt1 = flt2 ** str1 # error
int3 = int1 ** int2 # disabled in Cython
int3 = 3 ** 4 # disabled in Cython
_ERRORS = u""" _ERRORS = u"""
5:13: Invalid operand types for '**' (char *; float) 5:13: Invalid operand types for '**' (char *; float)
6:13: Invalid operand types for '**' (float; char *) 6:13: Invalid operand types for '**' (float; char *)
7:13: C has no integer powering, use python ints or floats instead '**' (int; int)
8:10: C has no integer powering, use python ints or floats instead '**' (long; long)
""" """
...@@ -8,16 +8,24 @@ __doc__ = u""" ...@@ -8,16 +8,24 @@ __doc__ = u"""
>>> h(4) >>> h(4)
625 625
>>> constant_py() == 2L ** 10 >>> constant_py() == 2 ** 10
True True
>>> constant_long() == 2L ** 36 >>> constant_long() == 2 ** 36
True True
"""
import sys >>> small_int_pow(3)
if sys.version_info[0] >= 3: (1, 3, 9, 27, 81)
__doc__ = __doc__.replace(u"2L", u"2") >>> small_int_pow(-5)
(1, -5, 25, -125, 625)
>>> int_pow(7, 2)
49
>>> int_pow(5, 3)
125
>>> int_pow(2, 10)
1024
"""
def f(obj2, obj3): def f(obj2, obj3):
cdef float flt1, flt2, flt3 cdef float flt1, flt2, flt3
...@@ -40,3 +48,9 @@ def constant_py(): ...@@ -40,3 +48,9 @@ def constant_py():
def constant_long(): def constant_long():
result = (<object>2L) ** 36 result = (<object>2L) ** 36
return result return result
def small_int_pow(long s):
return s**0, s**1, s**2, s**3, s**4
def int_pow(short a, short b):
return a**b
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment