本文整理汇总了Python中pypy.objspace.std.inttype.wrapint函数的典型用法代码示例。如果您正苦于以下问题:Python wrapint函数的具体用法?Python wrapint怎么用?Python wrapint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wrapint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_pow_iin
def test_pow_iin(self):
x = 10
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
v = self.space.pow(f1, f2, self.space.w_None)
assert v.intval == x ** y
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例2: test_and
def test_and(self):
x = 12345678
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
v = self.space.and_(f1, f2)
assert v.intval == x & y
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例3: test_rshift
def test_rshift(self):
x = 12345678
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
v = self.space.rshift(f1, f2)
assert v.intval == x >> y
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例4: test_mul
def test_mul(self):
for x in [0, 1, 100, sys.maxint // 2 - 50, sys.maxint - 1000]:
for y in [0, 1, 100, sys.maxint // 2 - 50, sys.maxint - 1000]:
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
result = self.space.unwrap(self.space.mul(f1, f2))
assert result == x*y and type(result) == type(x*y)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例5: test_or
def test_or(self):
x = 12345678
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
v = self.space.or_(f1, f2)
assert v.intval == x | y
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例6: test_div
def test_div(self):
for i in range(10):
res = i//3
f1 = wrapint(self.space, i)
f2 = wrapint(self.space, 3)
result = self.space.div(f1, f2)
assert result.intval == res
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例7: test_mod
def test_mod(self):
x = 1
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
v = self.space.mod(f1, f2)
assert v.intval == x % y
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_smallintobject.py
示例8: test_divmod
def test_divmod(self):
x = 1
y = 2
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
ret = self.space.divmod(f1, f2)
v, w = self.space.unwrap(ret)
assert (v, w) == divmod(x, y)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_smallintobject.py
示例9: test_add
def test_add(self):
for x in [1, 100, sys.maxint // 2 - 50,
sys.maxint // 2, sys.maxint - 1000, sys.maxint]:
for y in [1, 100, sys.maxint // 2 - 50,
sys.maxint // 2, sys.maxint - 1000, sys.maxint]:
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
result = self.space.unwrap(self.space.add(f1, f2))
assert result == x+y
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_smallintobject.py
示例10: len__RopeIter
def len__RopeIter(space, w_ropeiter):
if w_ropeiter.node is None:
return wrapint(space, 0)
index = w_ropeiter.index
length = w_ropeiter.node.length()
result = length - index
if result < 0:
return wrapint(space, 0)
return wrapint(space, result)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:ropeobject.py
示例11: test_abs
def test_abs(self):
x = 42
f1 = wrapint(self.space, x)
v = self.space.abs(f1)
assert v.intval == abs(x)
x = -42
f1 = wrapint(self.space, x)
v = self.space.abs(f1)
assert v.intval == abs(x)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_smallintobject.py
示例12: test_sub
def test_sub(self):
for x in [1, 100, sys.maxint // 2 - 50,
sys.maxint // 2, sys.maxint - 1000, sys.maxint]:
for y in [1, 100, sys.maxint // 2 - 50,
sys.maxint // 2, sys.maxint - 1000, sys.maxint]:
f1 = wrapint(self.space, x)
f2 = wrapint(self.space, y)
result = self.space.unwrap(self.space.sub(f1, f2))
assert result == x-y and type(result) == type(x-y)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_smallintobject.py
示例13: len__RangeIter
def len__RangeIter(space, w_rangeiter):
if w_rangeiter.w_rangelist is None:
return wrapint(space, 0)
index = w_rangeiter.index
w_length = space.len(w_rangeiter.w_rangelist)
w_len = space.sub(w_length, wrapint(space, index))
if space.is_true(space.lt(w_len, wrapint(space, 0))):
w_len = wrapint(space, 0)
return w_len
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:rangeobject.py
示例14: test_pos
def test_pos(self):
x = 42
f1 = wrapint(self.space, x)
v = self.space.pos(f1)
assert v.intval == +x
x = -42
f1 = wrapint(self.space, x)
v = self.space.pos(f1)
assert v.intval == +x
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_smallintobject.py
示例15: test_compare
def test_compare(self):
import operator
optab = ['lt', 'le', 'eq', 'ne', 'gt', 'ge']
for x in (-10, -1, 0, 1, 2, 1000, sys.maxint):
for y in (-sys.maxint-1, -11, -9, -2, 0, 1, 3, 1111, sys.maxint):
for op in optab:
wx = wrapint(self.space, x)
wy = wrapint(self.space, y)
res = getattr(operator, op)(x, y)
method = getattr(self.space, op)
myres = method(wx, wy)
assert self.space.unwrap(myres) == res
开发者ID:gorakhargosh,项目名称:pypy,代码行数:12,代码来源:test_smallintobject.py
示例16: neg__Int
def neg__Int(space, w_int1):
a = w_int1.intval
try:
x = ovfcheck(-a)
except OverflowError:
raise FailedToImplement(space.w_OverflowError, space.wrap("integer negation"))
return wrapint(space, x)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:intobject.py
示例17: str_rfind__Rope_Rope_ANY_ANY
def str_rfind__Rope_Rope_ANY_ANY(space, w_self, w_sub, w_start, w_end):
# XXX works but flattens
(self, sub, start, end) = _convert_idx_params(space, w_self, w_sub, w_start, w_end)
self = self.flatten_string()
sub = sub.flatten_string()
res = self.rfind(sub, start, end)
return wrapint(space, res)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:ropeobject.py
示例18: lshift__SmallInt_SmallInt
def lshift__SmallInt_SmallInt(space, w_int1, w_int2):
a = w_int1.intval
b = w_int2.intval
if b < 0:
raise OperationError(space.w_ValueError,
space.wrap("negative shift count"))
if a == 0 or b == 0:
return int__SmallInt(space, w_int1)
if b >= LONG_BIT:
raise FailedToImplement(space.w_OverflowError,
space.wrap("integer left shift"))
##
## XXX please! have a look into pyport.h and see how to implement
## the overflow checking, using macro Py_ARITHMETIC_RIGHT_SHIFT
## we *assume* that the overflow checking is done correctly
## in the code generator, which is not trivial!
## XXX also note that Python 2.3 returns a long and never raises
## OverflowError.
try:
c = ovfcheck_lshift(a, b)
## the test in C code is
## if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
## if (PyErr_Warn(PyExc_FutureWarning,
# and so on
except OverflowError:
raise FailedToImplement(space.w_OverflowError,
space.wrap("integer left shift"))
return wrapint(space, c)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:29,代码来源:smallintobject.py
示例19: _impl_int_int_pow
def _impl_int_int_pow(space, iv, iw, iz=0):
if iw < 0:
if iz != 0:
raise OperationError(
space.w_TypeError, space.wrap("pow() 2nd argument " "cannot be negative when 3rd argument specified")
)
## bounce it, since it always returns float
raise FailedToImplement(space.w_ValueError, space.wrap("integer exponentiation"))
temp = iv
ix = 1
try:
while iw > 0:
if iw & 1:
ix = ovfcheck(ix * temp)
iw >>= 1 # /* Shift exponent down by 1 bit */
if iw == 0:
break
temp = ovfcheck(temp * temp) # /* Square the value of temp */
if iz:
# /* If we did a multiplication, perform a modulo */
ix = ix % iz
temp = temp % iz
if iz:
ix = ix % iz
except OverflowError:
raise FailedToImplement(space.w_OverflowError, space.wrap("integer exponentiation"))
return wrapint(space, ix)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:27,代码来源:intobject.py
示例20: sub__Int_Int
def sub__Int_Int(space, w_int1, w_int2):
x = w_int1.intval
y = w_int2.intval
try:
z = ovfcheck(x - y)
except OverflowError:
raise FailedToImplementArgs(space.w_OverflowError, space.wrap("integer substraction"))
return wrapint(space, z)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:intobject.py
注:本文中的pypy.objspace.std.inttype.wrapint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论