aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/floatop.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2024-03-17 22:23:16 +0200
committerVeikka Tuominen <git@vexu.eu>2024-03-17 22:23:16 +0200
commitaa03ec8001f98ac36e1705c92191246be53cf31b (patch)
tree355b3ba639219120bfea75e04b05d04bf23d2841 /test/behavior/floatop.zig
parent8ac5eb0893b6db81003475245f7bcf449a5ed033 (diff)
downloadzig-aa03ec8001f98ac36e1705c92191246be53cf31b.tar.gz
zig-aa03ec8001f98ac36e1705c92191246be53cf31b.zip
add behavior test for optimized float math
Closes #19178
Diffstat (limited to 'test/behavior/floatop.zig')
-rw-r--r--test/behavior/floatop.zig21
1 files changed, 21 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);
+}