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