| ... | @@ -8,8 +8,6 @@ const builtin = @import("builtin"); | ... | @@ -8,8 +8,6 @@ const builtin = @import("builtin"); |
| 8 | const errol = @import("fmt/errol.zig"); | 8 | const errol = @import("fmt/errol.zig"); |
| 9 | const lossyCast = std.math.lossyCast; | 9 | const lossyCast = std.math.lossyCast; |
| 10 | | 10 | |
| 11 | const max_int_digits = 65; | | |
| 12 | | | |
| 13 | /// Renders fmt string with args, calling output with slices of bytes. | 11 | /// Renders fmt string with args, calling output with slices of bytes. |
| 14 | /// If `output` returns an error, the error is returned from `format` and | 12 | /// If `output` returns an error, the error is returned from `format` and |
| 15 | /// `output` is not called again. | 13 | /// `output` is not called again. |
| ... | @@ -731,9 +729,8 @@ fn formatIntUnsigned( | ... | @@ -731,9 +729,8 @@ fn formatIntUnsigned( |
| 731 | comptime Errors: type, | 729 | comptime Errors: type, |
| 732 | output: fn (@typeOf(context), []const u8) Errors!void, | 730 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 733 | ) Errors!void { | 731 | ) Errors!void { |
| 734 | // max_int_digits accounts for the minus sign. when printing an unsigned | 732 | assert(base >= 2); |
| 735 | // number we don't need to do that. | 733 | var buf: [math.max(@typeOf(value).bit_count, 1)]u8 = undefined; |
| 736 | var buf: [max_int_digits - 1]u8 = undefined; | | |
| 737 | const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count); | 734 | const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count); |
| 738 | const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); | 735 | const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); |
| 739 | var a: MinInt = value; | 736 | var a: MinInt = value; |
| ... | @@ -913,7 +910,7 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { | ... | @@ -913,7 +910,7 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 913 | } | 910 | } |
| 914 | | 911 | |
| 915 | test "buf print int" { | 912 | test "buf print int" { |
| 916 | var buffer: [max_int_digits]u8 = undefined; | 913 | var buffer: [100]u8 = undefined; |
| 917 | const buf = buffer[0..]; | 914 | const buf = buffer[0..]; |
| 918 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110")); | 915 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110")); |
| 919 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678")); | 916 | testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678")); |