authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-05 15:52:19+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-05 15:52:19+11:00
log4f58bfe1a81a385ac9120510b816ff081ab73437
tree1d20485d47f8f92b226e0464efd3a378723f4fa5
parentd5359ea541f83160e520ef030e33bfc104ec13e2
signature Commit is signed but in an unrecognized format.

std: fix formatting of i1 integers


1 files changed, 9 insertions(+), 9 deletions(-)

lib/std/fmt.zig+9-9
......@@ -943,19 +943,17 @@ fn formatIntSigned(
943943 .precision = options.precision,
944944 .fill = options.fill,
945945 };
946
947 const uint = std.meta.IntType(false, @TypeOf(value).bit_count);
946 const bit_count = @typeInfo(@TypeOf(value)).Int.bits;
947 const Uint = std.meta.IntType(false, bit_count);
948948 if (value < 0) {
949 const minus_sign: u8 = '-';
950 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
951 const new_value = @intCast(uint, -(value + 1)) + 1;
949 try output(context, "-");
950 const new_value = ~@bitCast(Uint, value +% -1);
952951 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
953952 } else if (options.width == null or options.width.? == 0) {
954 return formatIntUnsigned(@intCast(uint, value), base, uppercase, options, context, Errors, output);
953 return formatIntUnsigned(@intCast(Uint, value), base, uppercase, options, context, Errors, output);
955954 } else {
956 const plus_sign: u8 = '+';
957 try output(context, @as(*const [1]u8, &plus_sign)[0..]);
958 const new_value = @intCast(uint, value);
955 try output(context, "+");
956 const new_value = @intCast(Uint, value);
959957 return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output);
960958 }
961959}
......@@ -1166,6 +1164,8 @@ test "bufPrintInt" {
11661164 var buffer: [100]u8 = undefined;
11671165 const buf = buffer[0..];
11681166
1167 std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
1168
11691169 std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
11701170 std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
11711171 std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));