Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.fmt.parseFloat treats "." as valid float. #11713

Closed
ghost opened this issue May 25, 2022 · 2 comments
Closed

std.fmt.parseFloat treats "." as valid float. #11713

ghost opened this issue May 25, 2022 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@ghost
Copy link

ghost commented May 25, 2022

Zig Version

0.10.0-dev.1933+5f2d0d414

Steps to Reproduce

const std = @import("std");

test "" {
    const f = try std.fmt.parseFloat(f64, ".");
    try std.testing.expect(f == 0);
}

$ zig build test

Expected Behavior

I would expect this test to fail at the parseFloat call.

Actual Behavior

$ All 1 tests passed.

@ghost ghost added the bug Observed behavior contradicts documented or intended behavior label May 25, 2022
@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels May 25, 2022
@Vexu Vexu added this to the 0.11.0 milestone May 25, 2022
@arBmind
Copy link
Contributor

arBmind commented May 26, 2022

I added this test case in #11727 but could not reproduce this issue.

C:\Zig\Tests> C:\Zig\repo\stage1\bin\zig.exe test float.zig

Test [1/1] testTest [1/1] test ""... FAIL (InvalidCharacter)
FAIL (InvalidCharacter)
C:\Zig\repo\lib\std\fmt\parse_float\parse_float.zig:31:9: 0x7ff65c742161 in td.fmt.parse_float.parse_float.parseFloat (test.obj)
        return parse.parseInfOrNan(T, s[i..], negative) orelse error.InvalidCharacter;
        ^
C:\Zig\Tests\float.zig:4:15: 0x7ff65c74176c in est "" (test.obj)
    const f = try std.fmt.parseFloat(f64, ".");
              ^
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:

@tiehuis
Copy link
Member

tiehuis commented May 26, 2022

Your zig version is slightly out of date. A new float-parser has been recently implemented in master which fixes this issue: see #11566.

The following is true as of current; try testing.expectError(error.InvalidCharacter, parseFloat(f64, "."));.

@tiehuis tiehuis closed this as completed May 26, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.10.0 May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants