aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2024-09-17 14:34:10 +0100
committerGitHub <noreply@github.com>2024-09-17 14:34:10 +0100
commit41330c96aebddbf26d8fdc0725e7483476175601 (patch)
tree15b108f8983affc4933d60d6b0eaf6e2c2db35ee /test/behavior
parent812557bfde3c577b5f00cb556201c71ad5ed6fa4 (diff)
parent4650e5b9fcaa74b724a51458f5cf8952f3c734de (diff)
downloadzig-41330c96aebddbf26d8fdc0725e7483476175601.tar.gz
zig-41330c96aebddbf26d8fdc0725e7483476175601.zip
Merge pull request #21428 from mlugg/compare-to-undef
Sema: return undefined on comparison of runtime value against undefined
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/math.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
index 5ee07b9e98..bbf87fc834 100644
--- a/test/behavior/math.zig
+++ b/test/behavior/math.zig
@@ -1729,3 +1729,65 @@ test "@clz works on both vector and scalar inputs" {
try std.testing.expectEqual(@as(u6, 31), a);
try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b);
}
+
+test "runtime comparison to NaN is comptime-known" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
+ if (builtin.cpu.arch.isArmOrThumb() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
+
+ const S = struct {
+ fn doTheTest(comptime F: type, x: F) void {
+ const nan = math.nan(F);
+ if (!(nan != x)) comptime unreachable;
+ if (nan == x) comptime unreachable;
+ if (nan > x) comptime unreachable;
+ if (nan < x) comptime unreachable;
+ if (nan >= x) comptime unreachable;
+ if (nan <= x) comptime unreachable;
+ }
+ };
+
+ S.doTheTest(f16, 123.0);
+ S.doTheTest(f32, 123.0);
+ S.doTheTest(f64, 123.0);
+ S.doTheTest(f128, 123.0);
+ comptime S.doTheTest(f16, 123.0);
+ comptime S.doTheTest(f32, 123.0);
+ comptime S.doTheTest(f64, 123.0);
+ comptime S.doTheTest(f128, 123.0);
+}
+
+test "runtime int comparison to inf is comptime-known" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
+ if (builtin.cpu.arch.isArmOrThumb() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
+
+ const S = struct {
+ fn doTheTest(comptime F: type, x: u32) void {
+ const inf = math.inf(F);
+ if (!(inf != x)) comptime unreachable;
+ if (inf == x) comptime unreachable;
+ if (x > inf) comptime unreachable;
+ if (x >= inf) comptime unreachable;
+ if (!(x < inf)) comptime unreachable;
+ if (!(x <= inf)) comptime unreachable;
+ }
+ };
+
+ S.doTheTest(f16, 123);
+ S.doTheTest(f32, 123);
+ S.doTheTest(f64, 123);
+ S.doTheTest(f128, 123);
+ comptime S.doTheTest(f16, 123);
+ comptime S.doTheTest(f32, 123);
+ comptime S.doTheTest(f64, 123);
+ comptime S.doTheTest(f128, 123);
+}