def unmarshal_long(space, u, tc): from rpython.rlib.rbigint import rbigint lng = u.get_int() if lng < 0: negative = True lng = -lng else: negative = False digits = [u.get_short() for i in range(lng)] result = rbigint.from_list_n_bits(digits, 15) if lng and not result.tobool(): raise oefmt(space.w_ValueError, "bad marshal data") if negative: result = result.neg() return space.newlong_from_rbigint(result)
def unmarshal_long(space, u, tc): from rpython.rlib.rbigint import rbigint lng = u.get_int() if lng < 0: negative = True lng = -lng else: negative = False digits = [u.get_short() for i in range(lng)] result = rbigint.from_list_n_bits(digits, 15) if lng and not result.tobool(): raise oefmt(space.w_ValueError, "bad marshal data") if negative: result = result.neg() return space.newlong_from_rbigint(result)
def unmarshal_Long(space, u, tc): from rpython.rlib.rbigint import rbigint lng = u.get_int() if lng < 0: negative = True lng = -lng else: negative = False digits = [u.get_short() for i in range(lng)] result = rbigint.from_list_n_bits(digits, 15) if lng and not result.tobool(): raise_exception(space, 'bad marshal data') if negative: result = result.neg() w_long = newlong(space, result) return w_long
for mask in masks_list: res3 = f1.abs_rshift_and_mask(r_ulonglong(y), mask) assert res3 == (abs(x) >> y) & mask def test_from_list_n_bits(self): for x in ([3L ** 30L, 5L ** 20L, 7 ** 300] + [1L << i for i in range(130)] + [(1L << i) - 1L for i in range(130)]): for nbits in range(1, SHIFT+1): mask = (1 << nbits) - 1 lst = [] got = x while got > 0: lst.append(int(got & mask)) got >>= nbits f1 = rbigint.from_list_n_bits(lst, nbits) assert f1.tolong() == x def test_bitwise(self): for x in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30]): for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 3 ** 31]): lx = rbigint.fromlong(x) ly = rbigint.fromlong(y) for mod in "xor and_ or_".split(): res1 = getattr(lx, mod)(ly).tolong() res2 = getattr(operator, mod)(x, y) assert res1 == res2 def test_int_bitwise(self): for x in gen_signs([0, 1, 5, 11, 42, 43, 2 ** 30]): for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 2 ** 31]):