# pypy / pypy / jit / metainterp / test / test_float.py

The branch 'autoreds' does not exist.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82``` ```import math, sys from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin from pypy.rlib.rarithmetic import intmask, r_uint class FloatTests: def test_simple(self): def f(a, b, c, d, e): return (((a + b) - c) * d) / e res = self.interp_operations(f, [41.5, 2.25, 17.5, 3.0, 2.5]) assert res == 31.5 def test_cast_bool_to_float(self): def f(a): return float(a == 12.0) res = self.interp_operations(f, [41.5]) assert res == 0.0 res = self.interp_operations(f, [12.0]) assert res == 1.0 def test_abs(self): def f(a): return abs(a) res = self.interp_operations(f, [-5.25]) assert res == 5.25 x = 281474976710656.31 res = self.interp_operations(f, [x]) assert res == x def test_neg(self): def f(a): return -a res = self.interp_operations(f, [-5.25]) assert res == 5.25 x = 281474976710656.31 res = self.interp_operations(f, [x]) assert res == -x def test_singlefloat(self): from pypy.rlib.rarithmetic import r_singlefloat def f(a): a = float(r_singlefloat(a)) a *= 4.25 return float(r_singlefloat(a)) res = self.interp_operations(f, [-2.0]) assert res == -8.5 def test_cast_float_to_int(self): def g(f): return int(f) res = self.interp_operations(g, [-12345.9]) assert res == -12345 def test_cast_float_to_uint(self): def g(f): return intmask(r_uint(f)) res = self.interp_operations(g, [sys.maxint*2.0]) assert res == intmask(long(sys.maxint*2.0)) res = self.interp_operations(g, [-12345.9]) assert res == -12345 def test_cast_int_to_float(self): def g(i): return float(i) res = self.interp_operations(g, [-12345]) assert type(res) is float and res == -12345.0 def test_cast_uint_to_float(self): def g(i): return float(r_uint(i)) res = self.interp_operations(g, [intmask(sys.maxint*2)]) assert type(res) is float and res == float(sys.maxint*2) res = self.interp_operations(g, [-12345]) assert type(res) is float and res == float(long(r_uint(-12345))) class TestOOtype(FloatTests, OOJitMixin): pass class TestLLtype(FloatTests, LLJitMixin): pass ```