| ... | @@ -414,3 +414,11 @@ pub fn skipToBoundary(pos: u64, boundary: u64, reader: anytype) !void { | ... | @@ -414,3 +414,11 @@ pub fn skipToBoundary(pos: u64, boundary: u64, reader: anytype) !void { |
| 414 | pub fn is(a: anytype, b: @TypeOf(a)) bool { | 414 | pub fn is(a: anytype, b: @TypeOf(a)) bool { |
| 415 | return a == b; | 415 | return a == b; |
| 416 | } | 416 | } |
| | 417 | |
| | 418 | /// Allows u32 + i16 to work |
| | 419 | pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) { |
| | 420 | if (b >= 0) { |
| | 421 | return a + @intCast(@TypeOf(a), b); |
| | 422 | } |
| | 423 | return a - @intCast(@TypeOf(a), -b); |
| | 424 | } |