• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rbigint.fromint函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: unique_id

 def unique_id(self, space):
     if self.user_overridden_class:
         return W_Object.unique_id(self, space)
     from pypy.objspace.std.model import IDTAG_INT as tag
     b = space.bigint_w(self)
     b = b.lshift(3).or_(rbigint.fromint(tag))
     return space.newlong_from_rbigint(b)
开发者ID:craigkerstiens,项目名称:pypy,代码行数:7,代码来源:intobject.py


示例17: test_conversions

    def test_conversions(self):
        for v in (0, 1, -1, sys.maxint, -sys.maxint-1):
            assert rbigint.fromlong(long(v)).tolong() == long(v)
            l = rbigint.fromint(v)
            assert l.toint() == v
            if v >= 0:
                u = l.touint()
                assert u == v
                assert type(u) is r_uint
            else:
                py.test.raises(ValueError, l.touint)

        toobig_lv1 = rbigint.fromlong(sys.maxint+1)
        assert toobig_lv1.tolong() == sys.maxint+1
        toobig_lv2 = rbigint.fromlong(sys.maxint+2)
        assert toobig_lv2.tolong() == sys.maxint+2
        toobig_lv3 = rbigint.fromlong(-sys.maxint-2)
        assert toobig_lv3.tolong() == -sys.maxint-2

        for lv in (toobig_lv1, toobig_lv2, toobig_lv3):
            py.test.raises(OverflowError, lv.toint)

        lmaxuint = rbigint.fromlong(2*sys.maxint+1)
        toobig_lv4 = rbigint.fromlong(2*sys.maxint+2)

        u = lmaxuint.touint()
        assert u == 2*sys.maxint+1

        py.test.raises(ValueError, toobig_lv3.touint)
        py.test.raises(OverflowError, toobig_lv4.touint)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:30,代码来源:test_rbigint.py


示例18: test_hash

 def test_hash(self):
     for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
               sys.maxint-3, sys.maxint-2, sys.maxint-1, sys.maxint,
               ] + [randint(0, sys.maxint) for _ in range(100)]:
         # hash of machine-sized integers
         assert rbigint.fromint(i).hash() == i
         # hash of negative machine-sized integers
         assert rbigint.fromint(-i-1).hash() == -i-1
     #
     for i in range(200):
         # hash of large integers: should be equal to the hash of the
         # integer reduced modulo 2**64-1, to make decimal.py happy
         x = randint(0, sys.maxint**5)
         y = x % (2**64-1)
         assert rbigint.fromlong(x).hash() == rbigint.fromlong(y).hash()
         assert rbigint.fromlong(-x).hash() == rbigint.fromlong(-y).hash()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:16,代码来源:test_rbigint.py


示例19: unique_id

 def unique_id(self, space):
     if self.user_overridden_class:
         return W_Object.unique_id(self, space)
     from pypy.rlib.longlong2float import float2longlong
     from pypy.objspace.std.model import IDTAG_FLOAT as tag
     val = float2longlong(space.float_w(self))
     b = rbigint.fromrarith_int(val)
     b = b.lshift(3).or_(rbigint.fromint(tag))
     return space.newlong_from_rbigint(b)
开发者ID:craigkerstiens,项目名称:pypy,代码行数:9,代码来源:floatobject.py


示例20: f

 def f(space, w_int1, w_float2):
     f2 = w_float2.floatval
     i1 = w_int1.intval
     f1 = float(i1)
     if LONG_BIT > 32 and int(f1) != i1:
         res = revcompare(f2, rbigint.fromint(i1))
     else:
         res = op(f1, f2)
     return space.newbool(res)
开发者ID:craigkerstiens,项目名称:pypy,代码行数:9,代码来源:floatobject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rbigint.fromlong函数代码示例发布时间:2022-05-27
下一篇:
Python rarithmetic.r_ulonglong函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap