authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-28 15:26:11-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-29 19:57:36+01:00
log5571c08e6603173378db7cfe1436e33e902f9c0a
tree627aa2c52410d462a5521822f7cd946dbfa6ef48
parent4d6f4e9cfd00669efc1c688d9509010ddc4e840f

add behavior test for i96 operations


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

test/behavior/math.zig+44
......@@ -1946,3 +1946,47 @@ test "comptime float vector multiplication of zero by nan is nan" {
19461946 comptime assert(math.isNan((ct_zero * ct_nan)[0]));
19471947 comptime assert(math.isNan((ct_nan * ct_zero)[0]));
19481948}
1949
1950test "i96 operations" {
1951 // This is coverage for some stuff used by std.Io timestamps, to catch
1952 // issues earlier than bootstrapping.
1953 const Op_i96 = union(enum) {
1954 a,
1955 b: B,
1956 c: C,
1957
1958 const B = struct {
1959 inner: struct { x: i96 },
1960 flag: bool,
1961 };
1962
1963 const C = struct {
1964 inner: struct { x: i96 },
1965 flag: bool,
1966 };
1967
1968 fn do(op: @This()) i64 {
1969 switch (op) {
1970 .a => {
1971 return std.math.minInt(i64);
1972 },
1973 .b => |b| {
1974 const x = b.inner.x;
1975 return @intCast(@divTrunc(x, 100));
1976 },
1977 .c => |c| {
1978 const a = get() catch unreachable;
1979 const b = a.x + c.inner.x;
1980 return @intCast(@divTrunc(b, 100));
1981 },
1982 }
1983 }
1984
1985 fn get() anyerror!struct { x: i96 } {
1986 return .{ .x = 999999999 };
1987 }
1988 };
1989 try expect(-9223372036854775808 == Op_i96.do(.{ .a = {} }));
1990 try expect(12345678910111213 == Op_i96.do(.{ .b = .{ .inner = .{ .x = 1234567891011121314 }, .flag = true } }));
1991 try expect(1234567891021121314 == Op_i96.do(.{ .c = .{ .inner = .{ .x = 123456789101112131415 }, .flag = true } }));
1992}