| ... | ... | @@ -1636,3 +1636,24 @@ test "runtime isNan(inf * 0)" { |
| 1636 | 1636 | const zero_times_inf = 0 * std.math.inf(f64); |
| 1637 | 1637 | try std.testing.expect(std.math.isNan(zero_times_inf)); |
| 1638 | 1638 | } |
| 1639 | |
| 1640 | test "optimized float mode" { |
| 1641 | if (builtin.mode == .Debug) return error.SkipZigTest; |
| 1642 | |
| 1643 | const big = 0x1p40; |
| 1644 | const small = 0.001; |
| 1645 | const tiny = 0x1p-10; |
| 1646 | |
| 1647 | const S = struct { |
| 1648 | fn strict(x: f64) f64 { |
| 1649 | @setFloatMode(.strict); |
| 1650 | return x + big - big; |
| 1651 | } |
| 1652 | fn optimized(x: f64) f64 { |
| 1653 | @setFloatMode(.optimized); |
| 1654 | return x + big - big; |
| 1655 | } |
| 1656 | }; |
| 1657 | try expect(S.optimized(small) == small); |
| 1658 | try expect(S.strict(small) == tiny); |
| 1659 | } |