def test_it_writes_a_float64_to_buffer(self, space): w_float64_type = ffitype.FloatRWStrategy(ffitype.FLOAT64) data = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw') w_f = space.newfloat(1e-12) w_float64_type.write(space, data, w_f) raw_res = misc.read_raw_float_data(data, 8) assert raw_res == 1e-12 lltype.free(data, flavor='raw')
def test_it_writes_a_float32_to_buffer(self, space): w_float32_type = ffitype.FloatRWStrategy(ffitype.FLOAT32) data = lltype.malloc(rffi.CCHARP.TO, 4, flavor='raw') w_f = space.newfloat(3.75) w_float32_type.write(space, data, w_f) raw_res = misc.read_raw_float_data(data, 4) assert raw_res == 3.75 lltype.free(data, flavor='raw')
def test_it_writes_a_float64_to_buffer(self, space): w_float64_type = ffitype.FloatRWStrategy(ffitype.FLOAT64) data = lltype.malloc(rffi.CCHARP.TO, 8, flavor='raw') w_f = space.newfloat(1e-12) w_float64_type.write(space, data, w_f) raw_res = misc.read_raw_float_data(data, 8) assert raw_res == 1e-12 lltype.free(data, flavor='raw')
def test_it_writes_a_float32_to_buffer(self, space): w_float32_type = ffitype.FloatRWStrategy(ffitype.FLOAT32) data = lltype.malloc(rffi.CCHARP.TO, 4, flavor='raw') w_f = space.newfloat(3.75) w_float32_type.write(space, data, w_f) raw_res = misc.read_raw_float_data(data, 4) assert raw_res == 3.75 lltype.free(data, flavor='raw')
def convert_to_object(self, cdata): value = misc.read_raw_float_data(cdata, self.size) return self.space.wrap(value)
def read(self, space, data): result = misc.read_raw_float_data(data, self.typesize) return space.newfloat(float(result))
def convert_to_object(self, cdata): halfsize = self.size >> 1 cdata2 = rffi.ptradd(cdata, halfsize) real = misc.read_raw_float_data(cdata, halfsize) imag = misc.read_raw_float_data(cdata2, halfsize) return self.space.newcomplex(real, imag)