Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
Depending on the signedness of the integertype, an integer formatted with a minimal width will include a '+' sign in an incorrect place. Disabling this '+' is not possible. Example code for comparison:
const std2 = @import("std");
var buffer: [20]u8 = undefined;
const len = std2.fmt.formatIntBuf(&buffer, @as(i64, 3), 10, .lower, .{.fill = '0', .width = 4});
std2.debug.print("{s}\n", .{buffer[0..len]});
const len2 = std2.fmt.formatIntBuf(&buffer, @as(u64, 3), 10, .lower, .{.fill = '0', .width = 4});
std2.debug.print("{s}\n", .{buffer[0..len2]});
Expected Behavior
In both cases I would expect a printed string "0003". However, in the case of the value 3 as typed i64, we get the string "00+3". This is obviously a wrong string. In my opinion there are two issues with the "00+3" output. First of all, if a plus sign is included it should be at the start, i.e. "+003". Second of all, the '+' sign should be an optional character. The c formatting specification has an option for an explicit '+' sign for numerical values. This should be the case for the Zig stdlib as well. In most cases, the '+' is not desired behavior, as we do not want to explicitly indicate that we are talking about a positive number. Therefore, '+" should be removed from default options and added only if explicitly indicated.
Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
Depending on the signedness of the integertype, an integer formatted with a minimal width will include a '+' sign in an incorrect place. Disabling this '+' is not possible. Example code for comparison:
Expected Behavior
In both cases I would expect a printed string "0003". However, in the case of the value 3 as typed i64, we get the string "00+3". This is obviously a wrong string. In my opinion there are two issues with the "00+3" output. First of all, if a plus sign is included it should be at the start, i.e. "+003". Second of all, the '+' sign should be an optional character. The c formatting specification has an option for an explicit '+' sign for numerical values. This should be the case for the Zig stdlib as well. In most cases, the '+' is not desired behavior, as we do not want to explicitly indicate that we are talking about a positive number. Therefore, '+" should be removed from default options and added only if explicitly indicated.