| 1 | import math |
| 2 | |
| 3 | fn test_round_to_even() { |
| 4 | assert math.round_to_even(0.123) == 0.0 |
| 5 | assert math.round_to_even(123.12345) == 123.00 |
| 6 | } |
| 7 | |
| 8 | fn test_rount_to_even_edge() { |
| 9 | vrounds_ := [f64(-0.0), 0.0, -0.5, 0.5, -1.0, 1.0, 0.12345, 1.2345, 12.345, 123.45, 1234.5, |
| 10 | 12345.0, -math.pi, math.pi, math.inf(-1), math.inf(1), |
| 11 | math.nan()] |
| 12 | rounds_ := [f64(0.0), 0.0, -0.0, 0.0, -1.0, 1.0, 0.0, 1.0, 12.0, 123.0, 1234.0, 12345, -3.0, |
| 13 | 3.0, math.inf(-1), math.inf(1), math.nan()] |
| 14 | for i, v in vrounds_ { |
| 15 | assert math.alike(math.round_to_even(v), rounds_[i]) |
| 16 | } |
| 17 | } |
| 18 | |