authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-09-04 12:31:55 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-09-04 12:31:55 -07:00
log7ef45fbcd11d2af38fa372137d45c2fd4d9e94b8
treeec160c395275eedfe1b9543a4c2f47837ce58690
parent74f0ddb0a4dfa7921739b88cc381951a6b6e73ce

add OneSmallerInt


2 files changed, 41 insertions(+), 0 deletions(-)

src/OneSmallerInt.zig created+40
......@@ -0,0 +1,40 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn OneSmallerInt(comptime T: type) type {
6 var info = @typeInfo(T);
7 info.Int.bits -= 1;
8 return @Type(info);
9}
10
11test {
12 try std.testing.expect(OneSmallerInt(u1) == u0);
13}
14test {
15 try std.testing.expect(OneSmallerInt(u2) == u1);
16}
17test {
18 try std.testing.expect(OneSmallerInt(u3) == u2);
19}
20test {
21 try std.testing.expect(OneSmallerInt(u4) == u3);
22}
23test {
24 try std.testing.expect(OneSmallerInt(u5) == u4);
25}
26test {
27 try std.testing.expect(OneSmallerInt(i1) == i0);
28}
29test {
30 try std.testing.expect(OneSmallerInt(i2) == i1);
31}
32test {
33 try std.testing.expect(OneSmallerInt(i3) == i2);
34}
35test {
36 try std.testing.expect(OneSmallerInt(i4) == i3);
37}
38test {
39 try std.testing.expect(OneSmallerInt(i5) == i4);
40}
src/lib.zig+1
......@@ -93,3 +93,4 @@ pub usingnamespace @import("./rawInt.zig");
9393pub usingnamespace @import("./expectSimilarType.zig");
9494pub usingnamespace @import("./rawIntBytes.zig");
9595pub usingnamespace @import("./globalOption.zig");
96pub usingnamespace @import("./OneSmallerInt.zig");