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

Python rarithmetic.r_singlefloat函数代码示例

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

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



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

示例1: test_r_singlefloat_eq

def test_r_singlefloat_eq():
    x = r_singlefloat(2.5)       # exact number
    y = r_singlefloat(2.5)
    assert x == y
    assert not x != y
    assert not x == 2.5
    assert x != 2.5
    py.test.raises(TypeError, "x>y")
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_rarithmetic.py


示例2: test_cast

    def test_cast(self):
        res = cast(SIZE_T, -1)
        assert type(res) is r_size_t
        assert res == r_size_t(-1)
        #
        res = cast(lltype.Signed, 42.5)
        assert res == 42
    
        res = cast(lltype.SingleFloat, 12.3)
        assert res == r_singlefloat(12.3)
        res = cast(lltype.SingleFloat, res)
        assert res == r_singlefloat(12.3)

        res = cast(lltype.Float, r_singlefloat(12.))
        assert res == 12.
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:test_rffi.py


示例3: test_single_float_args

 def test_single_float_args(self):
     """
         float sum_xy_float(float x, float y)
         {
             return x+y;
         }
     """
     from ctypes import c_float # this is used only to compute the expected result
     libfoo = self.get_libfoo()
     func = (libfoo, 'sum_xy_float', [types.float, types.float], types.float)
     x = r_singlefloat(12.34)
     y = r_singlefloat(56.78)
     res = self.call(func, [x, y], rffi.FLOAT, jitif=["singlefloats"])
     expected = c_float(c_float(12.34).value + c_float(56.78).value).value
     assert float(res) == expected
开发者ID:gorakhargosh,项目名称:pypy,代码行数:15,代码来源:test_libffi.py


示例4: test_contains_unsupported_variable_type

def test_contains_unsupported_variable_type():
    def f(x):
        return x
    graph = support.getgraph(f, [5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                assert not contains_unsupported_variable_type(graph, sf,
                                                              sll, ssf)
    #
    graph = support.getgraph(f, [5.5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res is not sf
    #
    graph = support.getgraph(f, [r_singlefloat(5.5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (not ssf)
    #
    graph = support.getgraph(f, [r_longlong(5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (sys.maxint == 2147483647 and not sll)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:30,代码来源:test_policy.py


示例5: _singlefloat

 def _singlefloat(self, w_ffitype, w_obj):
     # a separate function, which can be seen by the jit or not,
     # depending on whether singlefloats are supported
     from pypy.rlib.rarithmetic import r_singlefloat
     floatval = self.space.float_w(w_obj)
     singlefloatval = r_singlefloat(floatval)
     self.handle_singlefloat(w_ffitype, w_obj, singlefloatval)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:type_converter.py


示例6: test_annotation_to_lltype

def test_annotation_to_lltype():
    from pypy.rlib.rarithmetic import r_uint, r_singlefloat
    s_i = SomeInteger()
    s_pos = SomeInteger(nonneg=True)
    s_1 = SomeInteger(nonneg=True); s_1.const = 1
    s_m1 = SomeInteger(nonneg=False); s_m1.const = -1
    s_u = SomeInteger(nonneg=True, unsigned=True); 
    s_u1 = SomeInteger(nonneg=True, unsigned=True); 
    s_u1.const = r_uint(1)
    assert annotation_to_lltype(s_i) == lltype.Signed
    assert annotation_to_lltype(s_pos) == lltype.Signed
    assert annotation_to_lltype(s_1) == lltype.Signed
    assert annotation_to_lltype(s_m1) == lltype.Signed
    assert annotation_to_lltype(s_u) == lltype.Unsigned
    assert annotation_to_lltype(s_u1) == lltype.Unsigned
    assert annotation_to_lltype(SomeBool()) == lltype.Bool
    assert annotation_to_lltype(SomeChar()) == lltype.Char
    PS = lltype.Ptr(lltype.GcStruct('s'))
    s_p = SomePtr(ll_ptrtype=PS)
    assert annotation_to_lltype(s_p) == PS
    py.test.raises(ValueError, "annotation_to_lltype(si0)")
    C = ootype.Instance('C', ROOT, {})
    ref = SomeOOInstance(C)
    assert annotation_to_lltype(ref) == C
    s_singlefloat = SomeSingleFloat()
    s_singlefloat.const = r_singlefloat(0.0)
    assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_model.py


示例7: arg_singlefloat

 def arg_singlefloat(self, space, argchain, w_arg):
     # a separate function, which can be seen by the jit or not,
     # depending on whether singlefloats are supported
     from pypy.rlib.rarithmetic import r_singlefloat
     fval = space.float_w(w_arg)
     sfval = r_singlefloat(fval)
     argchain.arg(sfval)
开发者ID:Sherlockhlt,项目名称:pypy,代码行数:7,代码来源:interp_ffi.py


示例8: test_wrap

def test_wrap():
    def _is(box1, box2):
        return box1.__class__ == box2.__class__ and box1.value == box2.value

    p = lltype.malloc(lltype.GcStruct("S"))
    po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
    assert _is(wrap(None, 42), BoxInt(42))
    assert _is(wrap(None, 42.5), boxfloat(42.5))
    assert _is(wrap(None, p), BoxPtr(po))
    assert _is(wrap(None, 42, in_const_box=True), ConstInt(42))
    assert _is(wrap(None, 42.5, in_const_box=True), constfloat(42.5))
    assert _is(wrap(None, p, in_const_box=True), ConstPtr(po))
    if longlong.supports_longlong:
        import sys
        from pypy.rlib.rarithmetic import r_longlong, r_ulonglong

        value = r_longlong(-sys.maxint * 17)
        assert _is(wrap(None, value), BoxFloat(value))
        assert _is(wrap(None, value, in_const_box=True), ConstFloat(value))
        value_unsigned = r_ulonglong(-sys.maxint * 17)
        assert _is(wrap(None, value_unsigned), BoxFloat(value))
    sfval = r_singlefloat(42.5)
    ival = longlong.singlefloat2int(sfval)
    assert _is(wrap(None, sfval), BoxInt(ival))
    assert _is(wrap(None, sfval, in_const_box=True), ConstInt(ival))
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:test_warmstate.py


示例9: detect_floatformat

def detect_floatformat():
    from pypy.rpython.lltypesystem import rffi, lltype
    buf = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw')
    rffi.cast(rffi.DOUBLEP, buf)[0] = 9006104071832581.0
    packed = rffi.charpsize2str(buf, 8)
    if packed == "\x43\x3f\xff\x01\x02\x03\x04\x05":
        double_format = 'IEEE, big-endian'
    elif packed == "\x05\x04\x03\x02\x01\xff\x3f\x43":
        double_format = 'IEEE, little-endian'
    else:
        double_format = 'unknown'
    lltype.free(buf, flavor='raw')
    #
    buf = lltype.malloc(rffi.CCHARP.TO, 4, flavor='raw')
    rffi.cast(rffi.FLOATP, buf)[0] = rarithmetic.r_singlefloat(16711938.0)
    packed = rffi.charpsize2str(buf, 4)
    if packed == "\x4b\x7f\x01\x02":
        float_format = 'IEEE, big-endian'
    elif packed == "\x02\x01\x7f\x4b":
        float_format = 'IEEE, little-endian'
    else:
        float_format = 'unknown'
    lltype.free(buf, flavor='raw')

    return double_format, float_format
开发者ID:gorakhargosh,项目名称:pypy,代码行数:25,代码来源:floattype.py


示例10: pack_float

def pack_float(fmtiter):
    doubleval = fmtiter.accept_float_arg()
    floatval = r_singlefloat(doubleval)
    float_buf[0] = floatval
    p = rffi.cast(rffi.CCHARP, float_buf)
    for i in range(sizeof_float):
        fmtiter.result.append(p[i])
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:nativefmttable.py


示例11: test_specialize_value

def test_specialize_value():
    assert specialize_value(lltype.Char, 0x41) == '\x41'
    if longlong.supports_longlong:
        import sys
        value = longlong.r_float_storage(sys.maxint*17)
        assert specialize_value(lltype.SignedLongLong, value) == sys.maxint*17
    sfval = r_singlefloat(42.5)
    ival = longlong.singlefloat2int(sfval)
    assert specialize_value(rffi.FLOAT, ival) == sfval
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_warmstate.py


示例12: test_call_with_singlefloats

    def test_call_with_singlefloats(self):
        cpu = self.cpu
        if not cpu.supports_floats or not cpu.supports_singlefloats:
            py.test.skip('requires floats and singlefloats')

        import random
        from pypy.rlib.libffi import types
        from pypy.rlib.rarithmetic import r_singlefloat

        def func(*args):
            res = 0.0
            for i, x in enumerate(args):
                res += (i + 1.1) * float(x)
            return res

        F = lltype.Float
        S = lltype.SingleFloat
        I = lltype.Signed
        floats = [random.random() - 0.5 for i in range(8)]
        singlefloats = [r_singlefloat(random.random() - 0.5) for i in range(8)]
        ints = [random.randrange(-99, 99) for i in range(8)]
        for repeat in range(100):
            args = []
            argvalues = []
            argslist = []
            local_floats = list(floats)
            local_singlefloats = list(singlefloats)
            local_ints = list(ints)
            for i in range(8):
                case = random.randrange(0, 3)
                if case == 0:
                    args.append(F)
                    arg = local_floats.pop()
                    argslist.append(boxfloat(arg))
                elif case == 1:
                    args.append(S)
                    arg = local_singlefloats.pop()
                    argslist.append(BoxInt(longlong.singlefloat2int(arg)))
                else:
                    args.append(I)
                    arg = local_ints.pop()
                    argslist.append(BoxInt(arg))
                argvalues.append(arg)
            FUNC = self.FuncType(args, F)
            FPTR = self.Ptr(FUNC)
            func_ptr = llhelper(FPTR, func)
            calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                        EffectInfo.MOST_GENERAL)
            funcbox = self.get_funcbox(cpu, func_ptr)

            res = self.execute_operation(rop.CALL,
                                         [funcbox] + argslist,
                                         'float', descr=calldescr)
            expected = func(*argvalues)
            assert abs(res.getfloat() - expected) < 0.0001
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:55,代码来源:calling_convention_test.py


示例13: pack_float

def pack_float(fmtiter):
    doubleval = fmtiter.accept_float_arg()
    floatval = r_singlefloat(doubleval)
    value = longlong2float.singlefloat2uint(floatval)
    value = widen(value)
    if fmtiter.bigendian:
        for i in range_4_unroll:
            x = (value >> (8*i)) & 0xff
            fmtiter.result.append(chr(x))
    else:
        for i in range_4_unroll:
            fmtiter.result.append(chr(value & 0xff))
            value >>= 8
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:nativefmttable.py


示例14: ctypes2lltype

def ctypes2lltype(T, cobj):
    """Convert the ctypes object 'cobj' to its lltype equivalent.
    'T' is the expected lltype type.
    """
    if isinstance(T, lltype.Ptr):
        if not cobj:   # NULL pointer
            return lltype.nullptr(T.TO)
        if isinstance(T.TO, lltype.Struct):
            if T.TO._arrayfld is not None:
                raise NotImplementedError("XXX var-sized structs")
            container = lltype._struct(T.TO)
            struct_use_ctypes_storage(container, cobj.contents)
        elif isinstance(T.TO, lltype.Array):
            if T.TO._hints.get('nolength', False):
                container = _array_of_unknown_length(T.TO)
                container._storage = cobj.contents
            else:
                raise NotImplementedError("array with an explicit length")
        elif isinstance(T.TO, lltype.FuncType):
            _callable = get_ctypes_trampoline(T.TO, cobj)
            return lltype.functionptr(T.TO, getattr(cobj, '__name__', '?'),
                                      _callable=_callable)
        elif isinstance(T.TO, lltype.OpaqueType):
            container = lltype._opaque(T.TO)
        else:
            raise NotImplementedError(T)
        llobj = lltype._ptr(T, container, solid=True)
    elif T is lltype.Char:
        llobj = chr(cobj)
    elif T is lltype.UniChar:
        llobj = unichr(cobj)
    elif T is lltype.Signed:
        llobj = cobj
    elif T is lltype.SingleFloat:
        if isinstance(cobj, ctypes.c_float):
            cobj = cobj.value
        llobj = r_singlefloat(cobj)
    else:
        from pypy.rpython.lltypesystem import rffi
        try:
            inttype = rffi.platform.numbertype_to_rclass[T]
        except KeyError:
            llobj = cobj
        else:
            llobj = inttype(cobj)

    assert lltype.typeOf(llobj) == T
    return llobj
开发者ID:antoine1fr,项目名称:pygirl,代码行数:48,代码来源:ll2ctypes.py


示例15: test_struct_fields_singlefloat

 def test_struct_fields_singlefloat(self):
     POINT = lltype.Struct('POINT',
                           ('x', rffi.FLOAT),
                           ('y', rffi.FLOAT)
                           )
     y_ofs = 4
     p = lltype.malloc(POINT, flavor='raw')
     p.x = r_singlefloat(123.4)
     p.y = r_singlefloat(567.8)
     addr = rffi.cast(rffi.VOIDP, p)
     assert struct_getfield_singlefloat(types.double, addr, 0) == r_singlefloat(123.4)
     assert struct_getfield_singlefloat(types.double, addr, y_ofs) == r_singlefloat(567.8)
     #
     struct_setfield_singlefloat(types.double, addr, 0, r_singlefloat(321.0))
     struct_setfield_singlefloat(types.double, addr, y_ofs, r_singlefloat(876.5))
     assert p.x == r_singlefloat(321.0)
     assert p.y == r_singlefloat(876.5)
     #
     lltype.free(p, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:19,代码来源:test_libffi.py


示例16: f

 def f(a):
     a = float(r_singlefloat(a))
     a *= 4.25
     return float(r_singlefloat(a))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:4,代码来源:test_float.py


示例17: f

 def f(x):
     a = r_singlefloat(x)
     b = r_singlefloat(x+1)
     return a == b
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:4,代码来源:test_rarithmetic.py


示例18: test_int_as_singlefloat

def test_int_as_singlefloat():
    for x in enum_floats():
        res = fnsingle(x)
        assert repr(res) == repr(float(r_singlefloat(x)))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:4,代码来源:test_longlong2float.py


示例19: test_r_singlefloat

def test_r_singlefloat():
    x = r_singlefloat(2.5)       # exact number
    assert float(x) == 2.5
    x = r_singlefloat(2.1)       # approximate number, bits are lost
    assert float(x) != 2.1
    assert abs(float(x) - 2.1) < 1E-6
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:6,代码来源:test_rarithmetic.py


示例20: __init__

 def __init__(self, space, default):
     if default:
         fval = float(rfloat.rstring_to_float(default))
     else:
         fval = float(0.)
     self.default = r_singlefloat(fval)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:6,代码来源:converter.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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