aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/floatop.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behavior/floatop.zig')
-rw-r--r--test/behavior/floatop.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig
index 22c576e5f5..85d5cec1e6 100644
--- a/test/behavior/floatop.zig
+++ b/test/behavior/floatop.zig
@@ -466,3 +466,32 @@ test "negation" {
try S.doTheTest();
comptime try S.doTheTest();
}
+
+test "eval @setFloatMode at compile-time" {
+ if (builtin.zig_backend != .stage1) {
+ // let's delay solving this one; I want to re-evaluate this language feature, and
+ // we don't rely on it for self-hosted.
+ return error.SkipZigTest; // TODO
+ }
+
+ const result = comptime fnWithFloatMode();
+ try expect(result == 1234.0);
+}
+
+fn fnWithFloatMode() f32 {
+ @setFloatMode(std.builtin.FloatMode.Strict);
+ return 1234.0;
+}
+
+test "float literal at compile time not lossy" {
+ if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+
+ try expect(16777216.0 + 1.0 == 16777217.0);
+ try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
+}
+
+test "f128 at compile time is lossy" {
+ if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+
+ try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
+}