authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 22:23:16+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-03-17 22:23:16+02:00
logaa03ec8001f98ac36e1705c92191246be53cf31b
tree355b3ba639219120bfea75e04b05d04bf23d2841
parent8ac5eb0893b6db81003475245f7bcf449a5ed033

add behavior test for optimized float math

Closes #19178

1 files changed, 21 insertions(+), 0 deletions(-)

test/behavior/floatop.zig+21
......@@ -1636,3 +1636,24 @@ test "runtime isNan(inf * 0)" {
16361636 const zero_times_inf = 0 * std.math.inf(f64);
16371637 try std.testing.expect(std.math.isNan(zero_times_inf));
16381638}
1639
1640test "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}