aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fmt/parse_float.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-06-13 20:39:40 -0400
committerGitHub <noreply@github.com>2021-06-13 20:39:40 -0400
commit86ebd4b975d2f1e01f468e06daab6e28c06f9719 (patch)
tree250bfe03e0768bdf7619fa8bb588b6815e1d3f0d /lib/std/fmt/parse_float.zig
parentdf4f11f42f44b4ee2a06e43095bc160277ceed42 (diff)
parente63ff4f1c110165c4b92025cb5b9d5531e861643 (diff)
downloadzig-86ebd4b975d2f1e01f468e06daab6e28c06f9719.tar.gz
zig-86ebd4b975d2f1e01f468e06daab6e28c06f9719.zip
Merge pull request #9106 from Vexu/fmt
Add formatting check to CI pipeline
Diffstat (limited to 'lib/std/fmt/parse_float.zig')
-rw-r--r--lib/std/fmt/parse_float.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig
index 3173d749b4..1f6d7222ac 100644
--- a/lib/std/fmt/parse_float.zig
+++ b/lib/std/fmt/parse_float.zig
@@ -34,7 +34,7 @@
// - Only supports round-to-zero
// - Does not handle denormals
-const std = @import("../std.zig");
+const std = @import("std");
const ascii = std.ascii;
// The mantissa field in FloatRepr is 64bit wide and holds only 19 digits
@@ -231,6 +231,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .LeadingFractionalZeros;
+ } else if (c == '_') {
+ i += 1;
} else {
state = .MantissaIntegral;
}
@@ -259,6 +261,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .MantissaFractional;
+ } else if (c == '_') {
+ i += 1;
} else {
state = .MantissaFractional;
}
@@ -276,6 +280,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == 'e' or c == 'E') {
i += 1;
state = .ExponentSign;
+ } else if (c == '_') {
+ i += 1;
} else {
state = .ExponentSign;
}
@@ -283,6 +289,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
.ExponentSign => {
if (c == '+') {
i += 1;
+ } else if (c == '_') {
+ return error.InvalidCharacter;
} else if (c == '-') {
negative_exp = true;
i += 1;
@@ -293,6 +301,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
.LeadingExponentZeros => {
if (c == '0') {
i += 1;
+ } else if (c == '_') {
+ i += 1;
} else {
state = .Exponent;
}
@@ -305,6 +315,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
}
i += 1;
+ } else if (c == '_') {
+ i += 1;
} else {
return error.InvalidCharacter;
}
@@ -405,6 +417,7 @@ test "fmt.parseFloat" {
try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
+ try expect(approxEqAbs(T, try parseFloat(T, "0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0"), @as(T, 123456.789000e10), epsilon));
if (T != f16) {
try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));