diff options
| author | Bas <BarabasGitHub@users.noreply.github.com> | 2020-09-08 11:56:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-08 11:56:59 +0200 |
| commit | 4a6ca735d9b3d466aba37c4488c1235b06a0bc84 (patch) | |
| tree | 10ef029ccaefe15c5152c1512a952ca6fdb01358 /lib/std/fmt/parse_float.zig | |
| parent | 0a40a61548ad9f666ed5300a8910f9040cc1390b (diff) | |
| parent | 389c26025283edef2206d19d9ad1ddc41e98f007 (diff) | |
| download | zig-4a6ca735d9b3d466aba37c4488c1235b06a0bc84.tar.gz zig-4a6ca735d9b3d466aba37c4488c1235b06a0bc84.zip | |
Merge branch 'master' into improve-windows-networking
Diffstat (limited to 'lib/std/fmt/parse_float.zig')
| -rw-r--r-- | lib/std/fmt/parse_float.zig | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig index 69557714f6..de17c60db6 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -37,7 +37,9 @@ const std = @import("../std.zig"); const ascii = std.ascii; -const max_digits = 25; +// The mantissa field in FloatRepr is 64bit wide and holds only 19 digits +// without overflowing +const max_digits = 19; const f64_plus_zero: u64 = 0x0000000000000000; const f64_minus_zero: u64 = 0x8000000000000000; @@ -372,7 +374,7 @@ test "fmt.parseFloat" { const epsilon = 1e-7; inline for ([_]type{ f16, f32, f64, f128 }) |T| { - const Z = std.meta.Int(false, T.bit_count); + const Z = std.meta.Int(false, @typeInfo(T).Float.bits); testing.expectError(error.InvalidCharacter, parseFloat(T, "")); testing.expectError(error.InvalidCharacter, parseFloat(T, " 1")); @@ -409,6 +411,7 @@ test "fmt.parseFloat" { expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); expect(approxEq(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon)); expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon)); + expect(approxEq(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon)); } } } |
