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


Python W_LongObject.fromfloat方法代码示例

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


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

示例1: descr_long

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
 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,代码行数:9,代码来源:floatobject.py

示例2: long__Float

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:12,代码来源:floatobject.py

示例3: eq__Float_Long

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:12,代码来源:floatobject.py

示例4: lt__Float_Long

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:13,代码来源:floatobject.py

示例5: _hash_float

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:49,代码来源:floatobject.py

示例6: float_as_integer_ratio__Float

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:26,代码来源:floatobject.py

示例7: long__Float

# 需要导入模块: from pypy.objspace.std.longobject import W_LongObject [as 别名]
# 或者: from pypy.objspace.std.longobject.W_LongObject import fromfloat [as 别名]
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,代码行数:8,代码来源:floatobject.py


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