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

Python longobject.W_LongObject类代码示例

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

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



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

示例1: pow_ovr

def pow_ovr(space, w_int1, w_int2):
    try:
        return _impl_pow(space, r_longlong(w_int1.intval), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.pow__Long_Long_None(space, w_a, w_b, space.w_None)
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:8,代码来源:smalllongobject.py


示例2: lshift_ovr

def lshift_ovr(space, w_int1, w_int2):
    a = r_longlong(w_int1.intval)
    try:
        return lshift__SmallLong_Int(space, W_SmallLongObject(a), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.lshift__Long_Long(space, w_a, w_b)
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:9,代码来源:smalllongobject.py


示例3: _pow_ovf2long

def _pow_ovf2long(space, iv, iw, w_modulus):
    if space.is_none(w_modulus) and _recover_with_smalllong(space):
        from pypy.objspace.std.smalllongobject import _pow as _pow_small
        try:
            # XXX: shouldn't have to pass r_longlong(0) here (see
            # 4fa4c6b93a84)
            return _pow_small(space, r_longlong(iv), iw, r_longlong(0))
        except (OverflowError, ValueError):
            pass
    from pypy.objspace.std.longobject import W_LongObject
    w_iv = W_LongObject.fromint(space, iv)
    w_iw = W_LongObject.fromint(space, iw)
    return w_iv.descr_pow(space, w_iw, w_modulus)
开发者ID:timfel,项目名称:thesis-data,代码行数:13,代码来源:intobject.py


示例4: ovf2long

    def ovf2long(space, x, y):
        """Handle overflowing to smalllong or long"""
        if _recover_with_smalllong(space):
            if ovf2small:
                return ovf2small(space, x, y)
            # Assume a generic operation without an explicit ovf2small
            # handler
            from pypy.objspace.std.smalllongobject import W_SmallLongObject
            a = r_longlong(x)
            b = r_longlong(y)
            return W_SmallLongObject(op(a, b))

        from pypy.objspace.std.longobject import W_LongObject
        w_x = W_LongObject.fromint(space, x)
        w_y = W_LongObject.fromint(space, y)
        return getattr(w_x, 'descr_' + opname)(space, w_y)
开发者ID:timfel,项目名称:thesis-data,代码行数:16,代码来源:intobject.py


示例5: descr_long

 def descr_long(self, space):
     try:
         return W_LongObject.fromfloat(space, self.floatval)
     except OverflowError:
         raise oefmt(space.w_OverflowError, "cannot convert float infinity to integer")
     except ValueError:
         raise oefmt(space.w_ValueError, "cannot convert float NaN to integer")
开发者ID:cimarieta,项目名称:usp,代码行数:7,代码来源:floatobject.py


示例6: wrap

 def wrap(self, x):
     "Wraps the Python value 'x' into one of the wrapper classes."
     # You might notice that this function is rather conspicuously
     # not RPython.  We can get away with this because the function
     # is specialized (see after the function body).  Also worth
     # noting is that the isinstance's involving integer types
     # behave rather differently to how you might expect during
     # annotation (see pypy/annotation/builtin.py)
     if x is None:
         return self.w_None
     if isinstance(x, OperationError):
         raise TypeError, ("attempt to wrap already wrapped exception: %s"%
                           (x,))
     if isinstance(x, int):
         if isinstance(x, bool):
             return self.newbool(x)
         else:
             return self.newint(x)
     if isinstance(x, str):
         # this hack is temporary: look at the comment in
         # test_stdstdobjspace.test_wrap_string
         try:
             unicode_x = x.decode('ascii')
         except UnicodeDecodeError:
             # poor man's x.decode('ascii', 'replace'), since it's not
             # supported by RPython
             if not we_are_translated():
                 print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x
             lst = []
             for ch in x:
                 ch = ord(ch)
                 if ch > 127:
                     lst.append(u'\ufffd')
                 else:
                     lst.append(unichr(ch))
             unicode_x = u''.join(lst)
         return wrapunicode(self, unicode_x)
     if isinstance(x, unicode):
         return wrapunicode(self, x)
     if isinstance(x, float):
         return W_FloatObject(x)
     if isinstance(x, W_Root):
         w_result = x.__spacebind__(self)
         #print 'wrapping', x, '->', w_result
         return w_result
     if isinstance(x, base_int):
         if self.config.objspace.std.withsmalllong:
             from pypy.objspace.std.smalllongobject import W_SmallLongObject
             from rpython.rlib.rarithmetic import r_longlong, r_ulonglong
             from rpython.rlib.rarithmetic import longlongmax
             if (not isinstance(x, r_ulonglong)
                 or x <= r_ulonglong(longlongmax)):
                 return W_SmallLongObject(r_longlong(x))
         x = widen(x)
         if isinstance(x, int):
             return self.newint(x)
         else:
             return W_LongObject.fromrarith_int(x)
     return self._wrap_not_rpython(x)
开发者ID:Qointum,项目名称:pypy,代码行数:59,代码来源:objspace.py


示例7: newbigint

def newbigint(space, w_longtype, bigint):
    """Turn the bigint into a W_LongObject.  If withsmalllong is enabled,
    check if the bigint would fit in a smalllong, and return a
    W_SmallLongObject instead if it does.  Similar to newlong() in
    longobject.py, but takes an explicit w_longtype argument.
    """
    if (space.config.objspace.std.withsmalllong
        and space.is_w(w_longtype, space.w_long)):
        try:
            z = bigint.tolonglong()
        except OverflowError:
            pass
        else:
            from pypy.objspace.std.smalllongobject import W_SmallLongObject
            return W_SmallLongObject(z)
    from pypy.objspace.std.longobject import W_LongObject
    w_obj = space.allocate_instance(W_LongObject, w_longtype)
    W_LongObject.__init__(w_obj, bigint)
    return w_obj
开发者ID:gorakhargosh,项目名称:pypy,代码行数:19,代码来源:longtype.py


示例8: long__Float

def long__Float(space, w_floatobj):
    try:
        return W_LongObject.fromfloat(space, w_floatobj.floatval)
    except OverflowError:
        if isnan(w_floatobj.floatval):
            raise OperationError(
                space.w_ValueError,
                space.wrap("cannot convert float NaN to integer"))
        raise OperationError(space.w_OverflowError,
                             space.wrap("cannot convert float infinity to long"))
开发者ID:craigkerstiens,项目名称:pypy,代码行数:10,代码来源:floatobject.py


示例9: eq__Float_Long

def eq__Float_Long(space, w_float1, w_long2):
    # XXX naive implementation
    x = w_float1.floatval
    if isinf(x) or math.floor(x) != x:
        return space.w_False
    try:
        w_long1 = W_LongObject.fromfloat(x)
    except OverflowError:
        return space.w_False
    return space.eq(w_long1, w_long2)
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:floatobject.py


示例10: lt__Float_Long

def lt__Float_Long(space, w_float1, w_long2):
    # XXX naive implementation
    x = w_float1.floatval
    if isinf(x):
        return space.newbool(x < 0.0)
    x_floor = math.floor(x)
    try:
        w_long1 = W_LongObject.fromfloat(x_floor)
    except OverflowError:
        return space.newbool(x < 0.0)
    return space.lt(w_long1, w_long2)
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:floatobject.py


示例11: wraplong

 def wraplong(self, x):
     "NOT_RPYTHON"
     if self.config.objspace.std.withsmalllong:
         from rpython.rlib.rarithmetic import r_longlong
         try:
             rx = r_longlong(x)
         except OverflowError:
             pass
         else:
             from pypy.objspace.std.smalllongobject import \
                                            W_SmallLongObject
             return W_SmallLongObject(rx)
     return W_LongObject.fromlong(x)
开发者ID:,项目名称:,代码行数:13,代码来源:


示例12: _hash_float

def _hash_float(space, v):
    from pypy.objspace.std.longobject import hash__Long

    if isnan(v):
        return 0

    # This is designed so that Python numbers of different types
    # that compare equal hash to the same value; otherwise comparisons
    # of mapping keys will turn out weird.
    fractpart, intpart = math.modf(v)

    if fractpart == 0.0:
        # This must return the same hash as an equal int or long.
        try:
            x = ovfcheck_float_to_int(intpart)
            # Fits in a C long == a Python int, so is its own hash.
            return x
        except OverflowError:
            # Convert to long and use its hash.
            try:
                w_lval = W_LongObject.fromfloat(space, v)
            except OverflowError:
                # can't convert to long int -- arbitrary
                if v < 0:
                    return -271828
                else:
                    return 314159
            return space.int_w(space.hash(w_lval))

    # The fractional part is non-zero, so we don't have to worry about
    # making this match the hash of some other type.
    # Use frexp to get at the bits in the double.
    # Since the VAX D double format has 56 mantissa bits, which is the
    # most of any double format in use, each of these parts may have as
    # many as (but no more than) 56 significant bits.
    # So, assuming sizeof(long) >= 4, each part can be broken into two
    # longs; frexp and multiplication are used to do that.
    # Also, since the Cray double format has 15 exponent bits, which is
    # the most of any double format in use, shifting the exponent field
    # left by 15 won't overflow a long (again assuming sizeof(long) >= 4).

    v, expo = math.frexp(v)
    v *= 2147483648.0  # 2**31
    hipart = int(v)    # take the top 32 bits
    v = (v - hipart) * 2147483648.0 # get the next 32 bits
    x = intmask(hipart + int(v) + (expo << 15))
    return x
开发者ID:craigkerstiens,项目名称:pypy,代码行数:47,代码来源:floatobject.py


示例13: wrap

 def wrap(self, x):
     "Wraps the Python value 'x' into one of the wrapper classes."
     # You might notice that this function is rather conspicuously
     # not RPython.  We can get away with this because the function
     # is specialized (see after the function body).  Also worth
     # noting is that the isinstance's involving integer types
     # behave rather differently to how you might expect during
     # annotation (see pypy/annotation/builtin.py)
     if x is None:
         return self.w_None
     if isinstance(x, model.W_Object):
         raise TypeError, "attempt to wrap already wrapped object: %s"%(x,)
     if isinstance(x, OperationError):
         raise TypeError, ("attempt to wrap already wrapped exception: %s"%
                           (x,))
     if isinstance(x, int):
         if isinstance(x, bool):
             return self.newbool(x)
         else:
             return self.newint(x)
     if isinstance(x, str):
         return wrapstr(self, x)
     if isinstance(x, unicode):
         return wrapunicode(self, x)
     if isinstance(x, float):
         return W_FloatObject(x)
     if isinstance(x, Wrappable):
         w_result = x.__spacebind__(self)
         #print 'wrapping', x, '->', w_result
         return w_result
     if isinstance(x, base_int):
         if self.config.objspace.std.withsmalllong:
             from pypy.objspace.std.smalllongobject import W_SmallLongObject
             from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
             from pypy.rlib.rarithmetic import longlongmax
             if (not isinstance(x, r_ulonglong)
                 or x <= r_ulonglong(longlongmax)):
                 return W_SmallLongObject(r_longlong(x))
         x = widen(x)
         if isinstance(x, int):
             return self.newint(x)
         else:
             return W_LongObject.fromrarith_int(x)
     return self._wrap_not_rpython(x)
开发者ID:,项目名称:,代码行数:44,代码来源:


示例14: float_as_integer_ratio__Float

def float_as_integer_ratio__Float(space, w_float):
    value = w_float.floatval
    if isinf(value):
        w_msg = space.wrap("cannot pass infinity to as_integer_ratio()")
        raise OperationError(space.w_OverflowError, w_msg)
    elif isnan(value):
        w_msg = space.wrap("cannot pass nan to as_integer_ratio()")
        raise OperationError(space.w_ValueError, w_msg)
    float_part, exp = math.frexp(value)
    for i in range(300):
        if float_part == math.floor(float_part):
            break
        float_part *= 2.0
        exp -= 1
    w_num = W_LongObject.fromfloat(space, float_part)
    w_den = space.newlong(1)
    w_exp = space.newlong(abs(exp))
    w_exp = space.lshift(w_den, w_exp)
    if exp > 0:
        w_num = space.mul(w_num, w_exp)
    else:
        w_den = w_exp
    # Try to return int.
    return space.newtuple([space.int(w_num), space.int(w_den)])
开发者ID:craigkerstiens,项目名称:pypy,代码行数:24,代码来源:floatobject.py


示例15: descr_long

 def descr_long(self, space):
     # XXX: should try smalllong
     from pypy.objspace.std.longobject import W_LongObject
     return W_LongObject.fromint(space, self.intval)
开发者ID:timfel,项目名称:thesis-data,代码行数:4,代码来源:intobject.py


示例16: newlong

 def newlong(self, val): # val is an int
     if self.config.objspace.std.withsmalllong:
         from pypy.objspace.std.smalllongobject import W_SmallLongObject
         return W_SmallLongObject.fromint(val)
     return W_LongObject.fromint(self, val)
开发者ID:,项目名称:,代码行数:5,代码来源:


示例17: long__Float

def long__Float(space, w_floatobj):
    try:
        return W_LongObject.fromfloat(w_floatobj.floatval)
    except OverflowError:
        raise OperationError(space.w_OverflowError,
                             space.wrap("cannot convert float infinity to long"))
开发者ID:alkorzt,项目名称:pypy,代码行数:6,代码来源:floatobject.py


示例18: _wrap_not_rpython

    def _wrap_not_rpython(self, x):
        "NOT_RPYTHON"
        # _____ this code is here to support testing only _____

        # wrap() of a container works on CPython, but the code is
        # not RPython.  Don't use -- it is kept around mostly for tests.
        # Use instead newdict(), newlist(), newtuple().
        if isinstance(x, dict):
            items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()]
            r = self.newdict()
            r.initialize_content(items_w)
            return r
        if isinstance(x, tuple):
            wrappeditems = [self.wrap(item) for item in list(x)]
            return self.newtuple(wrappeditems)
        if isinstance(x, list):
            wrappeditems = [self.wrap(item) for item in x]
            return self.newlist(wrappeditems)

        # The following cases are even stranger.
        # Really really only for tests.
        if type(x) is long:
            if self.config.objspace.std.withsmalllong:
                from pypy.rlib.rarithmetic import r_longlong
                try:
                    rx = r_longlong(x)
                except OverflowError:
                    pass
                else:
                    from pypy.objspace.std.smalllongobject import \
                                                   W_SmallLongObject
                    return W_SmallLongObject(rx)
            return W_LongObject.fromlong(x)
        if isinstance(x, slice):
            return W_SliceObject(self.wrap(x.start),
                                 self.wrap(x.stop),
                                 self.wrap(x.step))
        if isinstance(x, complex):
            return W_ComplexObject(x.real, x.imag)

        if isinstance(x, set):
            rdict_w = r_dict(self.eq_w, self.hash_w)
            for item in x:
                rdict_w[self.wrap(item)] = None
            res = W_SetObject(self, rdict_w)
            return res

        if isinstance(x, frozenset):
            wrappeditems = [self.wrap(item) for item in x]
            return W_FrozensetObject(self, wrappeditems)

        if x is __builtin__.Ellipsis:
            # '__builtin__.Ellipsis' avoids confusion with special.Ellipsis
            return self.w_Ellipsis

        if self.config.objspace.nofaking:
            raise OperationError(self.w_RuntimeError,
                                 self.wrap("nofaking enabled: refusing "
                                           "to wrap cpython value %r" %(x,)))
        if isinstance(x, type(Exception)) and issubclass(x, Exception):
            w_result = self.wrap_exception_cls(x)
            if w_result is not None:
                return w_result
        from pypy.objspace.std.fake import fake_object
        return fake_object(self, x)
开发者ID:,项目名称:,代码行数:65,代码来源:


示例19: OperationError

            except ParseStringError, e:
                raise OperationError(space.w_ValueError,
                                     space.wrap(e.msg))
        else:
            # otherwise, use the __long__() method
            w_obj = space.long(w_value)
            # 'long(x)' should return whatever x.__long__() returned
            if space.is_w(w_longtype, space.w_long):
                return w_obj
            if space.is_true(space.isinstance(w_obj, space.w_long)):
                assert isinstance(w_obj, W_LongObject)  # XXX this could fail!
                # XXX find a way to do that even if w_obj is not a W_LongObject
                w_value = w_obj
            elif space.is_true(space.isinstance(w_obj, space.w_int)):
                intval = space.int_w(w_obj)
                w_value = W_LongObject.fromint(space, intval)
            else:
                raise OperationError(space.w_ValueError,
                                    space.wrap("value can't be converted to long"))
    else:
        base = space.int_w(w_base)

        if space.is_true(space.isinstance(w_value, space.w_unicode)):
            from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
            s = unicode_to_decimal_w(space, w_value)
        else:
            try:
                s = space.str_w(w_value)
            except OperationError, e:
                raise OperationError(space.w_TypeError,
                                     space.wrap("long() can't convert non-string "
开发者ID:alkorzt,项目名称:pypy,代码行数:31,代码来源:longtype.py


示例20: newlong_from_rarith_int

 def newlong_from_rarith_int(self, val):  # val is an rarithmetic type
     return W_LongObject.fromrarith_int(val)
开发者ID:mozillazg,项目名称:pypy,代码行数:2,代码来源:objspace.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python model.registerimplementation函数代码示例发布时间:2022-05-27
下一篇:
Python listobject.W_ListObject类代码示例发布时间: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