authorgravatar for yujiri@disroot.orgEvin Yulo <yujiri@disroot.org> 2023-03-15 12:53:53-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-16 19:36:06+02:00
logb3af5d076c24744bdd100c25eabfea2a1a4688cf
tree0281f22527f068adeba204c706affd26b676be2d
parentda0509750a332806cfddad24b88ae8900782185d

Fix #14901: parseFloat parsing `0x` successfully


2 files changed, 3 insertions(+), 0 deletions(-)

lib/std/fmt/parse_float.zig+1
......@@ -119,6 +119,7 @@ test "fmt.parseFloat hex.f16" {
119119}
120120
121121test "fmt.parseFloat hex.f32" {
122 try testing.expectError(error.InvalidCharacter, parseFloat(f32, "0x"));
122123 try testing.expectEqual(try parseFloat(f32, "0x1p0"), 1.0);
123124 try testing.expectEqual(try parseFloat(f32, "-0x1p-1"), -0.5);
124125 try testing.expectEqual(try parseFloat(f32, "0x10p+10"), 16384.0);
lib/std/fmt/parse_float/parse.zig+2
......@@ -107,6 +107,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool
107107 tryParseDigits(MantissaT, stream, &mantissa, info.base);
108108 var int_end = stream.offsetTrue();
109109 var n_digits = @intCast(isize, stream.offsetTrue());
110 // the base being 16 implies a 0x prefix, which shouldn't be included in the digit count
111 if (info.base == 16) n_digits -= 2;
110112
111113 // handle dot with the following digits
112114 var exponent: i64 = 0;