本文整理汇总了Python中pypy.rlib.rbigint.rbigint.fromlong函数的典型用法代码示例。如果您正苦于以下问题:Python fromlong函数的具体用法?Python fromlong怎么用?Python fromlong使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromlong函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_str
def test_str(self):
for i in range(100):
n = 3 ** i
r1 = rbigint.fromlong(n)
assert r1.str() == str(n)
r2 = rbigint.fromlong(-n)
assert r2.str() == str(-n)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_rbigint.py
示例2: test_lt
def test_lt(self):
val = [0, 0x111111111111, 0x111111111112, 0x111111111112FFFF]
for x in gen_signs(val):
for y in gen_signs(val):
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
assert (x < y) == f1.lt(f2)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_rbigint.py
示例3: test_parse_digit_string
def test_parse_digit_string(self):
from pypy.rlib.rbigint import parse_digit_string
class Parser:
def __init__(self, base, sign, digits):
self.base = base
self.sign = sign
self.next_digit = iter(digits + [-1]).next
x = parse_digit_string(Parser(10, 1, [6]))
assert x.eq(rbigint.fromint(6))
x = parse_digit_string(Parser(10, 1, [6, 2, 3]))
assert x.eq(rbigint.fromint(623))
x = parse_digit_string(Parser(10, -1, [6, 2, 3]))
assert x.eq(rbigint.fromint(-623))
x = parse_digit_string(Parser(16, 1, [0xA, 0x4, 0xF]))
assert x.eq(rbigint.fromint(0xA4F))
num = 0
for i in range(36):
x = parse_digit_string(Parser(36, 1, range(i)))
assert x.eq(rbigint.fromlong(num))
num = num * 36 + i
x = parse_digit_string(Parser(16, -1, range(15,-1,-1)*99))
assert x.eq(rbigint.fromlong(long('-0x' + 'FEDCBA9876543210'*99, 16)))
assert x.tobool() is True
x = parse_digit_string(Parser(7, 1, [0, 0, 0]))
assert x.tobool() is False
x = parse_digit_string(Parser(7, -1, [0, 0, 0]))
assert x.tobool() is False
开发者ID:gorakhargosh,项目名称:pypy,代码行数:27,代码来源:test_rbigint.py
示例4: test_pow_lln
def test_pow_lln(self):
x = 10L
y = 2L
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
v = f1.pow(f2)
assert v.tolong() == x ** y
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_rbigint.py
示例5: test_invert
def test_invert(self):
x = 3 ** 40
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(-x)
r1 = f1.invert()
r2 = f2.invert()
assert r1.tolong() == -(x + 1)
assert r2.tolong() == -(-x + 1)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py
示例6: test_tofloat
def test_tofloat(self):
x = 12345678901234567890L ** 10
f1 = rbigint.fromlong(x)
d = f1.tofloat()
assert d == float(x)
x = x ** 100
f1 = rbigint.fromlong(x)
assert raises(OverflowError, f1.tofloat)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py
示例7: test_sub
def test_sub(self):
x = 12378959520302182384345L
y = 88961284756491823819191823L
for i in [-1, 1]:
for j in [-1, 1]:
f1 = rbigint.fromlong(x * i)
f2 = rbigint.fromlong(y * j)
result = f1.sub(f2)
assert result.tolong() == x * i - y * j
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_rbigint.py
示例8: test_add
def test_add(self):
x = 123456789123456789000000L
y = 123858582373821923936744221L
for i in [-1, 1]:
for j in [-1, 1]:
f1 = rbigint.fromlong(x * i)
f2 = rbigint.fromlong(y * j)
result = f1.add(f2)
assert result.tolong() == x * i + y * j
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_rbigint.py
示例9: test_bitwise
def test_bitwise(self):
for x in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30]):
for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 3 ** 31]):
lx = rbigint.fromlong(x)
ly = rbigint.fromlong(y)
for mod in "xor and_ or_".split():
res1 = getattr(lx, mod)(ly).tolong()
res2 = getattr(operator, mod)(x, y)
assert res1 == res2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_rbigint.py
示例10: test_truediv_overflow2
def test_truediv_overflow2(self):
overflowing = 2**1024 - 2**(1024-53-1)
op1 = rbigint.fromlong(2*overflowing - 10)
op2 = rbigint.fromlong(2)
f = op1.truediv(op2)
assert f == 1.7976931348623157e+308 # exactly
op2 = rbigint.fromlong(-2)
f = op1.truediv(op2)
assert f == -1.7976931348623157e+308 # exactly
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_rbigint.py
示例11: test_ulonglongmask
def test_ulonglongmask(self):
assert rbigint.fromlong(-1).ulonglongmask() == r_ulonglong(-1)
assert rbigint.fromlong(0).ulonglongmask() == r_ulonglong(0)
assert (rbigint.fromlong(sys.maxint).ulonglongmask() ==
r_ulonglong(sys.maxint))
assert (rbigint.fromlong(9**50).ulonglongmask() ==
r_ulonglong(9**50))
assert (rbigint.fromlong(-9**50).ulonglongmask() ==
r_ulonglong(-9**50))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_rbigint.py
示例12: test_mul
def test_mul(self):
x = -1238585838347L
y = 585839391919233L
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
result = f1.mul(f2)
assert result.tolong() == x * y
# also test a * a, it has special code
result = f1.mul(f1)
assert result.tolong() == x * x
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:10,代码来源:test_rbigint.py
示例13: test__x_divrem
def test__x_divrem(self):
x = 12345678901234567890L
for i in range(100):
y = long(randint(0, 1 << 30))
y <<= 30
y += randint(0, 1 << 30)
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
div, rem = lobj._x_divrem(f1, f2)
assert div.tolong(), rem.tolong() == divmod(x, y)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:10,代码来源:test_rbigint.py
示例14: test_longlong
def test_longlong(self):
max = 1L << (r_longlong.BITS-1)
f1 = rbigint.fromlong(max-1) # fits in r_longlong
f2 = rbigint.fromlong(-max) # fits in r_longlong
f3 = rbigint.fromlong(max) # overflows
f4 = rbigint.fromlong(-max-1) # overflows
assert f1.tolonglong() == max-1
assert f2.tolonglong() == -max
py.test.raises(OverflowError, f3.tolonglong)
py.test.raises(OverflowError, f4.tolonglong)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:10,代码来源:test_rbigint.py
示例15: test_eq
def test_eq(self):
x = 5858393919192332223L
y = 585839391919233111223311112332L
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(-x)
f3 = rbigint.fromlong(y)
assert f1.eq(f1)
assert f2.eq(f2)
assert f3.eq(f3)
assert not f1.eq(f2)
assert not f1.eq(f3)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:11,代码来源:test_rbigint.py
示例16: test_int_conversion
def test_int_conversion(self):
f1 = rbigint.fromlong(12332)
f2 = rbigint.fromint(12332)
assert f2.tolong() == f1.tolong()
assert f2.toint()
assert rbigint.fromlong(42).tolong() == 42
assert rbigint.fromlong(-42).tolong() == -42
u = f2.touint()
assert u == 12332
assert type(u) is r_uint
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:11,代码来源:test_rbigint.py
示例17: test_tofloat
def test_tofloat(self):
x = 12345678901234567890L ** 10
f1 = rbigint.fromlong(x)
d = f1.tofloat()
assert d == float(x)
x = x ** 100
f1 = rbigint.fromlong(x)
assert raises(OverflowError, f1.tofloat)
f2 = rbigint([0, 2097152], 1)
d = f2.tofloat()
assert d == float(2097152 << SHIFT)
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_rbigint.py
示例18: test_args_from_uint
def test_args_from_uint(self):
BASE = 1 << SHIFT
assert rbigint.fromrarith_int(r_uint(0)).eq(rbigint([0], 0))
assert rbigint.fromrarith_int(r_uint(17)).eq(rbigint([17], 1))
assert rbigint.fromrarith_int(r_uint(BASE-1)).eq(rbigint([BASE-1], 1))
assert rbigint.fromrarith_int(r_uint(BASE)).eq(rbigint([0, 1], 1))
assert rbigint.fromrarith_int(r_uint(BASE**2)).eq(rbigint([0, 0, 1], 1))
assert rbigint.fromrarith_int(r_uint(sys.maxint)).eq(
rbigint.fromint(sys.maxint))
assert rbigint.fromrarith_int(r_uint(sys.maxint+1)).eq(
rbigint.fromlong(sys.maxint+1))
assert rbigint.fromrarith_int(r_uint(2*sys.maxint+1)).eq(
rbigint.fromlong(2*sys.maxint+1))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:13,代码来源:test_rbigint.py
示例19: test__divrem
def test__divrem(self):
x = 12345678901234567890L
for i in range(100):
y = long(randint(0, 1 << 30))
y <<= 30
y += randint(0, 1 << 30)
for sx, sy in (1, 1), (1, -1), (-1, -1), (-1, 1):
sx *= x
sy *= y
f1 = rbigint.fromlong(sx)
f2 = rbigint.fromlong(sy)
div, rem = lobj._x_divrem(f1, f2)
assert div.tolong(), rem.tolong() == divmod(sx, sy)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:13,代码来源:test_rbigint.py
示例20: test_pow_lll
def test_pow_lll(self):
x = 10L
y = 2L
z = 13L
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
f3 = rbigint.fromlong(z)
v = f1.pow(f2, f3)
assert v.tolong() == pow(x, y, z)
f3n = f3.neg()
v = f1.pow(f2, f3n)
assert v.tolong() == pow(x, y, -z)
#
f1, f2, f3 = [rbigint.fromlong(i)
for i in (10L, -1L, 42L)]
py.test.raises(TypeError, f1.pow, f2, f3)
f1, f2, f3 = [rbigint.fromlong(i)
for i in (10L, 5L, 0L)]
py.test.raises(ValueError, f1.pow, f2, f3)
#
MAX = 1E40
x = long(random() * MAX) + 1
y = long(random() * MAX) + 1
z = long(random() * MAX) + 1
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
f3 = rbigint.fromlong(z)
print f1
print f2
print f3
v = f1.pow(f2, f3)
print '--->', v
assert v.tolong() == pow(x, y, z)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:33,代码来源:test_rbigint.py
注:本文中的pypy.rlib.rbigint.rbigint.fromlong函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论