| author | |
| committer | |
| log | cb7f0d0d5d65b7ea9304aea232bb2f5383f0356a |
| tree | c25e2a61e2318d14d2570c82d6366772e048a6a6 |
| parent | 20a6bcda25842a129b6447b8ab852104e07edad7 |
1 files changed, 8 insertions(+), 0 deletions(-)
src/lib.zig+8| ... | ... | @@ -414,3 +414,11 @@ pub fn skipToBoundary(pos: u64, boundary: u64, reader: anytype) !void { |
| 414 | 414 | pub fn is(a: anytype, b: @TypeOf(a)) bool { |
| 415 | 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 | } |