Skip to content

std.fmt.parseFloat does not parse 9007199254740993.0 correctly #11169

@andrewrk

Description

@andrewrk

Implementation is here: https://github.com/ziglang/zig/blob/master/lib/std/fmt/parse_float.zig

--- a/lib/std/fmt/parse_float.zig
+++ b/lib/std/fmt/parse_float.zig
@@ -425,4 +425,6 @@ test "fmt.parseFloat" {
             try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
         }
     }
+
+    try expectEqual(try parseFloat(f128, "9007199254740993.0"), 9007199254740993.0);
 }
$ ./zig test ../lib/std/fmt/parse_float.zig 
Test [1/1] test "parseFloat"... expected 9.007199254740994e+15, found 9.007199254740992e+15
Test [1/1] test "parseFloat"... FAIL (TestExpectedEqual)

This is causing a behavior test failure in the self-hosted compiler, which relies on std.fmt.parseFloat:

try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions