Пример #1
0
def test_call_stubs_single_float():
    from pypy.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from pypy.rlib.rarithmetic import r_singlefloat, intmask
    #
    c0 = GcCache(False)
    ARGS = [lltype.SingleFloat, lltype.SingleFloat, lltype.SingleFloat]
    RES = lltype.SingleFloat

    def f(a, b, c):
        a = float(a)
        b = float(b)
        c = float(c)
        x = a - (b / c)
        return r_singlefloat(x)

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = intmask(singlefloat2uint(r_singlefloat(-10.0)))
    b = intmask(singlefloat2uint(r_singlefloat(3.0)))
    c = intmask(singlefloat2uint(r_singlefloat(2.0)))
    res = descr2.call_stub(rffi.cast(lltype.Signed, fnptr),
                           [a, b, c], [], [])
    assert float(uint2singlefloat(rffi.r_uint(res))) == -11.5
Пример #2
0
def test_call_stubs_single_float():
    from pypy.rlib.longlong2float import uint2singlefloat, singlefloat2uint
    from pypy.rlib.rarithmetic import r_singlefloat, intmask
    #
    c0 = GcCache(False)
    ARGS = [lltype.SingleFloat, lltype.SingleFloat, lltype.SingleFloat]
    RES = lltype.SingleFloat

    def f(a, b, c):
        a = float(a)
        b = float(b)
        c = float(c)
        x = a - (b / c)
        return r_singlefloat(x)

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = intmask(singlefloat2uint(r_singlefloat(-10.0)))
    b = intmask(singlefloat2uint(r_singlefloat(3.0)))
    c = intmask(singlefloat2uint(r_singlefloat(2.0)))
    res = descr2.call_stub_i(rffi.cast(lltype.Signed, fnptr), [a, b, c], [],
                             [])
    assert float(uint2singlefloat(rffi.r_uint(res))) == -11.5
Пример #3
0
def fnsingle(f1):
    sf1 = r_singlefloat(f1)
    ii = singlefloat2uint(sf1)
    sf2 = uint2singlefloat(ii)
    f2 = float(sf2)
    return f2
Пример #4
0
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)
Пример #5
0
def fnsingle(f1):
    sf1 = r_singlefloat(f1)
    ii = singlefloat2uint(sf1)
    sf2 = uint2singlefloat(ii)
    f2 = float(sf2)
    return f2
Пример #6
0
def int2singlefloat(x):
    x = rffi.r_uint(x)
    return longlong2float.uint2singlefloat(x)