当前位置: 首页>>代码示例>>Python>>正文


Python rbigint.fromint函数代码示例

本文整理汇总了Python中pypy.rlib.rbigint.rbigint.fromint函数的典型用法代码示例。如果您正苦于以下问题:Python fromint函数的具体用法?Python fromint怎么用?Python fromint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fromint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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

示例2: test_order

 def test_order(self):
     f6 = rbigint.fromint(6)
     f7 = rbigint.fromint(7)
     assert (f6.lt(f6), f6.lt(f7), f7.lt(f6)) == (0,1,0)
     assert (f6.le(f6), f6.le(f7), f7.le(f6)) == (1,1,0)
     assert (f6.gt(f6), f6.gt(f7), f7.gt(f6)) == (0,0,1)
     assert (f6.ge(f6), f6.ge(f7), f7.ge(f6)) == (1,0,1)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_rbigint.py

示例3: test_uintmask

 def test_uintmask(self):
     assert rbigint.fromint(-1).uintmask() == r_uint(-1)
     assert rbigint.fromint(0).uintmask() == r_uint(0)
     assert (rbigint.fromint(sys.maxint).uintmask() ==
             r_uint(sys.maxint))
     assert (rbigint.fromlong(sys.maxint+1).uintmask() ==
             r_uint(-sys.maxint-1))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_rbigint.py

示例4: test_floordiv

 def test_floordiv(self):
     for op1 in [-12, -2, -1, 1, 2, 50]:
         for op2 in [-4, -2, -1, 1, 2, 8]:
             rl_op1 = rbigint.fromint(op1)
             rl_op2 = rbigint.fromint(op2)
             r1 = rl_op1.floordiv(rl_op2)
             r2 = op1 // op2
             assert r1.tolong() == r2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py

示例5: test_truediv

 def test_truediv(self):
     for op1 in [-12, -2, -1, 1, 2, 50]:
         for op2 in [-4, -2, -1, 1, 2, 8]:
             rl_op1 = rbigint.fromint(op1)
             rl_op2 = rbigint.fromint(op2)
             r1 = rl_op1.truediv(rl_op2)
             r2 = op1 / op2
             assert r1 == r2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py

示例6: test_pow

 def test_pow(self):
     for op1 in [-50, -12, -2, -1, 1, 2, 50, 52]:
         for op2 in [0, 1, 2, 8, 9, 10, 11]:
             rl_op1 = rbigint.fromint(op1)
             rl_op2 = rbigint.fromint(op2)
             r1 = rl_op1.pow(rl_op2)
             r2 = op1 ** op2
             assert r1.tolong() == r2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py

示例7: test_mod

 def test_mod(self):
     for op1 in [-50, -12, -2, -1, 1, 2, 50, 52]:
         for op2 in [-4, -2, -1, 1, 2, 8]:
             rl_op1 = rbigint.fromint(op1)
             rl_op2 = rbigint.fromint(op2)
             r1 = rl_op1.mod(rl_op2)
             r2 = op1 % op2
             assert r1.tolong() == r2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:8,代码来源:test_rbigint.py

示例8: test_simple

 def test_simple(self):
     for op1 in [-2, -1, 0, 1, 2, 50]:
         for op2 in [-2, -1, 0, 1, 2, 50]:
             rl_op1 = rbigint.fromint(op1)
             rl_op2 = rbigint.fromint(op2)
             for op in "add sub mul".split():
                 r1 = getattr(rl_op1, op)(rl_op2)
                 r2 = getattr(operator, op)(op1, op2)
                 assert r1.tolong() == r2
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:test_rbigint.py

示例9: test_add

 def test_add(self):
     x = rbigint.fromint(-2147483647)
     y = rbigint.fromint(-1)
     z = rbigint.fromint(-2147483648)
     def test():
         return x.add(y).eq(z)
     assert test()
     res = interpret(test, [])
     assert res
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_rbigint.py

示例10: test_bigint_w

 def test_bigint_w(self):
     space = self.space
     fromlong = lobj.W_LongObject.fromlong
     assert isinstance(space.bigint_w(fromlong(42)), rbigint)
     assert space.bigint_w(fromlong(42)).eq(rbigint.fromint(42))
     assert space.bigint_w(fromlong(-1)).eq(rbigint.fromint(-1))
     w_obj = space.wrap("hello world")
     space.raises_w(space.w_TypeError, space.bigint_w, w_obj)
     w_obj = space.wrap(123.456)
     space.raises_w(space.w_TypeError, space.bigint_w, w_obj)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_longobject.py

示例11: test_bigint_w

def test_bigint_w():
    space = CPyObjSpace()
    r1 = space.bigint_w(space.newlong(42))
    assert isinstance(r1, rbigint)
    assert r1.eq(rbigint.fromint(42))
    # cpython digit size
    assert space.bigint_w(space.newlong(2**8)).eq(rbigint.fromint(2**8))
    # rpython digit size
    assert space.bigint_w(space.newlong(2**15)).eq(rbigint.fromint(2**15))
    # and negative numbers
    assert space.bigint_w(space.newlong(-1)).eq(rbigint.fromint(-1))
    assert space.bigint_w(space.newlong(-2**8)).eq(rbigint.fromint(-2**8))
    assert space.bigint_w(space.newlong(-2**15)).eq(rbigint.fromlong(-2**15))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:13,代码来源:test_objspace.py

示例12: _PyLong_FromByteArray

def _PyLong_FromByteArray(space, bytes, n, little_endian, signed):
    little_endian = rffi.cast(lltype.Signed, little_endian)
    signed = rffi.cast(lltype.Signed, signed)

    result = rbigint()
    negative = False

    for i in range(0, n):
        if little_endian:
            c = intmask(bytes[i])
        else:
            c = intmask(bytes[n - i - 1])
        if i == 0 and signed and c & 0x80:
            negative = True
        if negative:
            c = c ^ 0xFF
        digit = rbigint.fromint(c)

        result = result.lshift(8)
        result = result.add(digit)

    if negative:
        result = result.neg()

    return space.newlong_from_rbigint(result)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:longobject.py

示例13: immutable_unique_id

 def immutable_unique_id(self, space):
     if self.user_overridden_class:
         return None
     from pypy.objspace.std.model import IDTAG_LONG as tag
     b = space.bigint_w(self)
     b = b.lshift(3).or_(rbigint.fromint(tag))
     return space.newlong_from_rbigint(b)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:longobject.py

示例14: pow__Long_Long_None

def pow__Long_Long_None(space, w_long1, w_long2, w_long3):
    # XXX need to replicate some of the logic, to get the errors right
    if w_long2.num.lt(rbigint.fromint(0)):
        raise FailedToImplementArgs(
            space.w_ValueError,
            space.wrap("long pow() too negative"))
    return W_LongObject(w_long1.num.pow(w_long2.num, None))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:longobject.py

示例15: imod

	def imod( self, other ):
		if self.bvalue:
			if other.bvalue:
				return HybridCell( 0, self.bvalue.mod( other.bvalue ) )
			else:
				o = rbigint.fromint(other.ivalue)
				v = self.bvalue.mod( o )
				return HybridCell( 0, v )
		else:
			if other.bvalue:
				s = rbigint.fromint(self.ivalue)
				v = s.mod( other.bvalue )
				return HybridCell( 0, v )
			else:
				v = self.ivalue % other.ivalue
				return HybridCell( v )
开发者ID:terrence2,项目名称:befunge2010,代码行数:16,代码来源:Cell.py


注:本文中的pypy.rlib.rbigint.rbigint.fromint函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。