diff options
| author | Veikka Tuominen <git@vexu.eu> | 2024-03-18 04:27:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-18 04:27:39 +0200 |
| commit | 64173dadcacdcad9b7f5898fee2b00f2cf177ead (patch) | |
| tree | d848615ca50e00493863ad724d1555011aef3b1d /test | |
| parent | 54f6e74cda07a1153fd205afc8973665397f6cc7 (diff) | |
| parent | aa03ec8001f98ac36e1705c92191246be53cf31b (diff) | |
| download | zig-64173dadcacdcad9b7f5898fee2b00f2cf177ead.tar.gz zig-64173dadcacdcad9b7f5898fee2b00f2cf177ead.zip | |
Merge pull request #19334 from antlilja/llvm-fast-math
Fix setFloatMode in LLVM backend
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/floatop.zig | 21 | ||||
| -rw-r--r-- | test/cases/float_mode_optimized_reduce.zig | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index b3bdfb6d71..e777377786 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -1636,3 +1636,24 @@ test "runtime isNan(inf * 0)" { const zero_times_inf = 0 * std.math.inf(f64); try std.testing.expect(std.math.isNan(zero_times_inf)); } + +test "optimized float mode" { + if (builtin.mode == .Debug) return error.SkipZigTest; + + const big = 0x1p40; + const small = 0.001; + const tiny = 0x1p-10; + + const S = struct { + fn strict(x: f64) f64 { + @setFloatMode(.strict); + return x + big - big; + } + fn optimized(x: f64) f64 { + @setFloatMode(.optimized); + return x + big - big; + } + }; + try expect(S.optimized(small) == small); + try expect(S.strict(small) == tiny); +} diff --git a/test/cases/float_mode_optimized_reduce.zig b/test/cases/float_mode_optimized_reduce.zig new file mode 100644 index 0000000000..55d71f4709 --- /dev/null +++ b/test/cases/float_mode_optimized_reduce.zig @@ -0,0 +1,12 @@ +pub fn main() void { + var a: @Vector(2, f32) = @splat(5.0); + _ = &a; + + @setFloatMode(.optimized); + var b = @reduce(.Add, a); + _ = &b; +} + +// run +// backend=llvm +// |
