1. Pypy
  2. Untitled project
  3. pypy

Commits

David Schneider  committed ca5c756

add runner tests for cast_int_to_float and cast_float_to_int

  • Participants
  • Parent commits d8b79f0
  • Branches default

Comments (0)

Files changed (1)

File rpython/jit/backend/test/runner_test.py

View file
                                      [BoxPtr(x)], 'int').value
         assert res == -19
 
+    def test_cast_int_to_float(self):
+        if not self.cpu.supports_floats:
+            py.test.skip("requires floats")
+        for x in [-10, -1, 0, 3, 42, sys.maxint-1]:
+            res = self.execute_operation(rop.CAST_INT_TO_FLOAT,
+                                         [BoxInt(x)],  'float').value
+            assert longlong.getrealfloat(res) == float(x)
+            res = self.execute_operation(rop.CAST_INT_TO_FLOAT,
+                                         [ConstInt(x)],  'float').value
+            assert longlong.getrealfloat(res) == float(x)
+
+    def test_cast_float_to_int(self):
+        if not self.cpu.supports_floats:
+            py.test.skip("requires floats")
+        for x in [-24.23, -5.3, 0.0, 3.1234, 11.1, 0.1]:
+            v = longlong.getfloatstorage(x)
+            res = self.execute_operation(rop.CAST_FLOAT_TO_INT,
+                                         [BoxFloat(v)],  'int').value
+            assert res == int(x)
+            res = self.execute_operation(rop.CAST_FLOAT_TO_INT,
+                                         [ConstFloat(v)],  'int').value
+            assert res == int(x)
+
     def test_convert_float_bytes(self):
         if not self.cpu.supports_floats:
             py.test.skip("requires floats")