Open mattburman opened 1 year ago
I can get the new test case to pass.
diff --git a/fastfloat/parse.go b/fastfloat/parse.go
index b37838d..b8a0bbe 100644
--- a/fastfloat/parse.go
+++ b/fastfloat/parse.go
@@ -500,6 +500,15 @@ func Parse(s string) (float64, error) {
if expMinus {
exp = -exp
}
+ if d != uint64(f) {
+ // TODO comment.
+ // Fall back to standard parsing.
+ f, err := strconv.ParseFloat(s, 64)
+ if err != nil && !math.IsInf(f, 0) {
+ return 0, fmt.Errorf("cannot parse exponent in %q: %s", s, err)
+ }
+ return f, nil
+ }
f *= math.Pow10(int(exp))
if i >= uint(len(s)) {
if minus {
diff --git a/fastfloat/parse_test.go b/fastfloat/parse_test.go
index e4dfe2f..e06912a 100644
--- a/fastfloat/parse_test.go
+++ b/fastfloat/parse_test.go
@@ -445,6 +445,7 @@ func TestParseSuccess(t *testing.T) {
f("-123e456", math.Inf(-1)) // too big exponent
f("1e4", 1e4)
f("-1E-10", -1e-10)
+ f("8.54E-4", 8.54e-4)
// Fractional + exponent part
f("0.123e4", 0.123e4)
However, it does seem to go down the fallback route for some of the other test cases, which is not ideal and perhaps adversely affecting perf.
cc @valyala - would you be able to address this case? Or, let me know if my proposed fix is good enough and I can raise it as a PR. I believe a better option may exist but I'm not seeing it.
So far I've found mulitple apis I use which indeed respond with JSON number values like 8.54E-4
. I would have to use MarshalTo
to then parse it with strconv
to get around it.
Hi
Is it possible to maintain equivalence with strconv for values like
8.54E-4
?