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
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
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
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
def fnsingle(f1): sf1 = r_singlefloat(f1) ii = singlefloat2uint(sf1) sf2 = uint2singlefloat(ii) f2 = float(sf2) return f2
def singlefloat2int(x): x = longlong2float.singlefloat2uint(x) return rffi.cast(lltype.Signed, x)