| author | |
| committer | |
| log | 091aa54a3ed74b8a19f44ffb20e29c5f81de0c58 |
| tree | cb6a4e676ddf4ef394609d4bcf15765b67214389 |
| parent | e90583f5d17a5a841b7ed8e654af9ed8ce119de5 |
Closes #19379
Closes #180462 files changed, 4 insertions(+), 2 deletions(-)
lib/std/fmt.zig+2| ... | @@ -1839,6 +1839,8 @@ test comptimePrint { | ... | @@ -1839,6 +1839,8 @@ test comptimePrint { |
| 1839 | try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); | 1839 | try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); |
| 1840 | try std.testing.expectEqualStrings("30", comptimePrint("{d}", .{30.0})); | 1840 | try std.testing.expectEqualStrings("30", comptimePrint("{d}", .{30.0})); |
| 1841 | try std.testing.expectEqualStrings("30.0", comptimePrint("{d:3.1}", .{30.0})); | 1841 | try std.testing.expectEqualStrings("30.0", comptimePrint("{d:3.1}", .{30.0})); |
| 1842 | try std.testing.expectEqualStrings("0.05", comptimePrint("{d}", .{0.05})); | ||
| 1843 | try std.testing.expectEqualStrings("5e-2", comptimePrint("{e}", .{0.05})); | ||
| 1842 | } | 1844 | } |
| 1843 | 1845 | ||
| 1844 | test "parse u64 digit too big" { | 1846 | test "parse u64 digit too big" { |
lib/std/fmt/format_float.zig+2-2| ... | @@ -270,9 +270,9 @@ pub fn formatDecimal(buf: []u8, f_: FloatDecimal128, precision: ?usize) FormatEr | ... | @@ -270,9 +270,9 @@ pub fn formatDecimal(buf: []u8, f_: FloatDecimal128, precision: ?usize) FormatEr |
| 270 | 270 | ||
| 271 | // fixed bound: leading_digit(1) + point(1) | 271 | // fixed bound: leading_digit(1) + point(1) |
| 272 | const req_bytes = if (f.exponent >= 0) | 272 | const req_bytes = if (f.exponent >= 0) |
| 273 | 2 + @abs(f.exponent) + olength + (precision orelse 0) | 273 | @as(usize, 2) + @abs(f.exponent) + olength + (precision orelse 0) |
| 274 | else | 274 | else |
| 275 | 2 + @max(@abs(f.exponent) + olength, precision orelse 0); | 275 | @as(usize, 2) + @max(@abs(f.exponent) + olength, precision orelse 0); |
| 276 | if (buf.len < req_bytes) { | 276 | if (buf.len < req_bytes) { |
| 277 | return error.BufferTooSmall; | 277 | return error.BufferTooSmall; |
| 278 | } | 278 | } |