def test_at(): w_obj = bootstrap_class(0, varsized=True).as_class_get_shadow(space).new(1) foo = wrap("foo") w_obj.store(space, 0, foo) assert prim(AT, [w_obj, 1]) is foo w_obj = W_Float(1.1) foo = wrap(1) w_obj.store(space, 0, foo) assert prim(AT, [w_obj, 1]) == foo
def func(interp, s_frame, rcvr, arg): from rpython.rlib.rfloat import INFINITY # http://www.python.org/dev/peps/pep-0754/ try: return interp.space.wrap_float(math.ldexp(rcvr, arg)) except OverflowError: if rcvr >= 0.0: return W_Float(INFINITY) else: return W_Float(-INFINITY)
def test_float_at(): b = W_Float(64.0) r = b.fetch(space, 0) if isinstance(r, W_LargeIntegerWord): assert r.size() == 4 assert space.unwrap_int(r.at0(space, 0)) == 0 assert space.unwrap_int(r.at0(space, 1)) == 0 assert space.unwrap_int(r.at0(space, 2)) == 80 assert space.unwrap_int(r.at0(space, 3)) == 64 else: assert isinstance(r, W_SmallInteger) assert space.unwrap_int(r) == (80 << 16) + (64 << 24) r = b.fetch(space, 1) assert isinstance(r, W_SmallInteger) assert r.value == 0
def test_float_at_put(): target = W_Float(1.0) for f in [1.0, -1.0, 1.1, 64.4, -0.0, float('nan'), float('inf')]: source = W_Float(f) target.store(space, 0, source.fetch(space, 0)) target.store(space, 1, source.fetch(space, 1)) if math.isnan(f): assert math.isnan(target.value) else: assert target.value == f
def test_not_is_same_object(w_o1=None,w_o2=None): if w_o1 is None: w_o1 = W_PointersObject(space, None, 0) if w_o2 is None: w_o2 = W_PointersObject(space, None,0) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = W_SmallInteger(2) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1) w_o2 = W_Float(5.5) assert not w_o1.is_same_object(w_o2) assert not w_o2.is_same_object(w_o1)
def test_mirror_at(): w_obj = W_Float(1.1) foo = wrap(1) w_obj.store(space, 0, foo) assert prim(AT, [space.w_nil, w_obj, 1]) == foo
def test_float_hash(): target = W_Float(1.1) assert target.gethash() == W_Float(1.1).gethash() target.store(space, 0, space.wrap_int(42)) assert target.gethash() != W_Float(1.1).gethash()
def test_intfloat_notis_same_object(): test_not_is_same_object(W_SmallInteger(1), W_Float(1)) test_not_is_same_object(W_Float(100), W_SmallInteger(100)) test_not_is_same_object(W_Float(1.100), W_Float(1.200)) test_not_is_same_object(W_SmallInteger(101), W_SmallInteger(100))
def wrap_float(self, i): return W_Float(i)