zig icon indicating copy to clipboard operation
zig copied to clipboard

std.fmt.parseFloat parses "0x" as 0.0 instead of returning error

Open mj-64 opened this issue 2 years ago • 0 comments

Zig Version

0.11.0-dev.1898+36d47dd19

Steps to Reproduce and Observed Behavior

test "parseFloat" {
    try std.testing.expectEqual(std.fmt.parseFloat(f64, "0xff"), 255.0);
    try std.testing.expectError(std.fmt.ParseFloatError.InvalidCharacter, std.fmt.parseFloat(f64, "0x"));  
}

Test [1/1] test.simple test... expected error.InvalidCharacter, found 0.0e+00
Test [1/1] test.simple test... FAIL (TestUnexpectedError)

Expected Behavior

std.fmt.parseFloat(f64, "0x") should return InvalidCharacter, because "0x" is not a valid literal.

mj-64 avatar Mar 13 '23 08:03 mj-64