Skip to content

Commit

Permalink
atof: fix fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed May 27, 2024
1 parent e36945f commit e098fc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion go/mysql/fastparse/atof.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,13 @@ func Atof64(s string) (f float64, n int, err error) {
return f, n, nil
}
}
return f, n, strconv.ErrRange

// Eisel-Lemire is incapable of parsing this float accurately; we need to
// fall back to the slow path. Fortunately, we now know how many actual
// characters the float has (it's the value of `n`), so we can simply fall
// back to the standard library, which will do the slow parsing and will
// not return an error for trailing characters after the float, because
// we have truncated it.
f, err = strconv.ParseFloat(s[:n], 64)
return f, n, err
}
2 changes: 1 addition & 1 deletion go/mysql/fastparse/fastparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func TestParseFloat64(t *testing.T) {
{
input: "-",
expected: 0.0,
err: `strconv.ParseFloat: parsing "-": invalid syntax`,
err: strconv.ErrSyntax.Error(),
},
{
input: " 10",
Expand Down

0 comments on commit e098fc9

Please sign in to comment.