| 1 |
import math |
| 2 |
from rpython.jit.metainterp.test.support import LLJitMixin |
| 3 |
from rpython.rlib.rfloat import INFINITY, NAN |
| 4 |
|
| 5 |
class MathTests: |
| 6 |
|
| 7 |
def test_math_sqrt(self): |
| 8 |
def f(x): |
| 9 |
try: |
| 10 |
return math.sqrt(x) |
| 11 |
except ValueError: |
| 12 |
return -INFINITY |
| 13 |
|
| 14 |
res = self.interp_operations(f, [0.0]) |
| 15 |
assert res == 0.0 |
| 16 |
self.check_operations_history(call_pure_f=1) |
| 17 |
|
| 18 |
res = self.interp_operations(f, [25.0]) |
| 19 |
assert res == 5.0 |
| 20 |
self.check_operations_history(call_pure_f=1) |
| 21 |
|
| 22 |
res = self.interp_operations(f, [-0.0]) |
| 23 |
assert str(res) == '-0.0' |
| 24 |
self.check_operations_history(call_pure_f=1) |
| 25 |
|
| 26 |
res = self.interp_operations(f, [1000000.0]) |
| 27 |
assert res == 1000.0 |
| 28 |
self.check_operations_history(call_pure_f=1) |
| 29 |
|
| 30 |
res = self.interp_operations(f, [-1.0]) |
| 31 |
assert res == -INFINITY |
| 32 |
self.check_operations_history(call_pure_f=0) |
| 33 |
|
| 34 |
res = self.interp_operations(f, [INFINITY]) |
| 35 |
assert math.isinf(res) and not math.isnan(res) and res > 0.0 |
| 36 |
self.check_operations_history(call_pure_f=0) |
| 37 |
|
| 38 |
res = self.interp_operations(f, [NAN]) |
| 39 |
assert math.isnan(res) and not math.isinf(res) |
| 40 |
self.check_operations_history(call_pure_f=0) |
| 41 |
|
| 42 |
|
| 43 |
class TestLLtype(MathTests, LLJitMixin): |
| 44 |
pass |