5
>>> f(1.0, 2.95)[0] == f(1.0, 2.95)[1]
8
cdef float flt1, flt2, flt3
9
flt2, flt3 = obj2, obj3
34
>>> constant_py() == 2 ** 10
37
result = (<object>2) ** 10
43
>>> constant_long() == 2 ** 36
46
result = (<object>2L) ** 36
50
def small_int_pow(long s):
55
(1, -5, 25, -125, 625)
57
return s**0, s**1, s**2, s**3, s**4
61
def int_pow_cpow(short a, short b):
63
>>> int_pow_cpow(7, 2)
65
>>> int_pow_cpow(5, 3)
67
>>> int_pow_cpow(2, 10)
73
def int_pow(short a, short b):
87
Copied from CPython's test_descr.py
97
return 'I(%s)' % int(self)
98
def __pow__(self, other, mod=None):
100
return I(pow(int(self), int(other)))
102
return I(pow(int(self), int(other), int(mod)))
103
def __rpow__(self, other, mod=None):
105
return I(pow(int(other), int(self), mod))
107
return I(pow(int(other), int(self), int(mod)))
113
def optimised_pow2(n):
115
>>> optimised_pow2(0)
117
>>> optimised_pow2(1)
119
>>> optimised_pow2(10)
121
>>> optimised_pow2(30)
123
>>> print(repr(optimised_pow2(31)).rstrip('L'))
125
>>> print(repr(optimised_pow2(32)).rstrip('L'))
127
>>> print(repr(optimised_pow2(60)).rstrip('L'))
129
>>> print(repr(optimised_pow2(63)).rstrip('L'))
131
>>> print(repr(optimised_pow2(64)).rstrip('L'))
133
>>> print(repr(optimised_pow2(100)).rstrip('L'))
134
1267650600228229401496703205376
135
>>> optimised_pow2(30000) == 2 ** 30000
137
>>> optimised_pow2(-1)
139
>>> optimised_pow2(0.5) == 2 ** 0.5
141
>>> optimised_pow2('test') # doctest: +ELLIPSIS
142
Traceback (most recent call last):
143
TypeError: ...operand... **...
145
if isinstance(n, int) and 0 <= n < 1000:
146
assert isinstance(2.0 ** n, float), 'float %s' % n
147
assert isinstance(2 ** n, int), 'int %s' % n
151
def optimised_pow2_inplace(n):
153
>>> optimised_pow2_inplace(0)
155
>>> optimised_pow2_inplace(1)
157
>>> optimised_pow2_inplace(10)
159
>>> optimised_pow2_inplace(30)
161
>>> print(repr(optimised_pow2_inplace(32)).rstrip('L'))
163
>>> print(repr(optimised_pow2_inplace(100)).rstrip('L'))
164
1267650600228229401496703205376
165
>>> optimised_pow2_inplace(30000) == 2 ** 30000
167
>>> optimised_pow2_inplace(-1)
169
>>> optimised_pow2_inplace(0.5) == 2 ** 0.5
171
>>> optimised_pow2_inplace('test') # doctest: +ELLIPSIS
172
Traceback (most recent call last):
173
TypeError: ...operand... **...