| author | |
| committer | |
| log | b3af5d076c24744bdd100c25eabfea2a1a4688cf |
| tree | 0281f22527f068adeba204c706affd26b676be2d |
| parent | da0509750a332806cfddad24b88ae8900782185d |
2 files changed, 3 insertions(+), 0 deletions(-)
lib/std/fmt/parse_float.zig+1| ... | @@ -119,6 +119,7 @@ test "fmt.parseFloat hex.f16" { | ... | @@ -119,6 +119,7 @@ test "fmt.parseFloat hex.f16" { |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | test "fmt.parseFloat hex.f32" { | 121 | test "fmt.parseFloat hex.f32" { |
| 122 | try testing.expectError(error.InvalidCharacter, parseFloat(f32, "0x")); | ||
| 122 | try testing.expectEqual(try parseFloat(f32, "0x1p0"), 1.0); | 123 | try testing.expectEqual(try parseFloat(f32, "0x1p0"), 1.0); |
| 123 | try testing.expectEqual(try parseFloat(f32, "-0x1p-1"), -0.5); | 124 | try testing.expectEqual(try parseFloat(f32, "-0x1p-1"), -0.5); |
| 124 | try testing.expectEqual(try parseFloat(f32, "0x10p+10"), 16384.0); | 125 | 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 | ... | @@ -107,6 +107,8 @@ fn parsePartialNumberBase(comptime T: type, stream: *FloatStream, negative: bool |
| 107 | tryParseDigits(MantissaT, stream, &mantissa, info.base); | 107 | tryParseDigits(MantissaT, stream, &mantissa, info.base); |
| 108 | var int_end = stream.offsetTrue(); | 108 | var int_end = stream.offsetTrue(); |
| 109 | var n_digits = @intCast(isize, stream.offsetTrue()); | 109 | 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; | ||
| 110 | 112 | ||
| 111 | // handle dot with the following digits | 113 | // handle dot with the following digits |
| 112 | var exponent: i64 = 0; | 114 | var exponent: i64 = 0; |