Skip to content

Commit 8b3ab7d

Browse files
Fix fastfloat parsing for -1234. (#6)
1 parent 28117b5 commit 8b3ab7d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

fastfloat/parse.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ func ParseBestEffort(s string) float64 {
271271
if i >= uint(len(s)) {
272272
// the fractional part may be elided to remain compliant
273273
// with https://go.dev/ref/spec#Floating-point_literals
274+
if minus {
275+
f = -f
276+
}
274277
return f
275278
}
276279
k := i
@@ -429,6 +432,9 @@ func Parse(s string) (float64, error) {
429432
if i >= uint(len(s)) {
430433
// the fractional part might be elided to remain compliant
431434
// with https://go.dev/ref/spec#Floating-point_literals
435+
if minus {
436+
f = -f
437+
}
432438
return f, nil
433439
}
434440
k := i

fastfloat/parse_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func TestParseBestEffort(t *testing.T) {
264264
f("12.", 12)
265265
f(".12", 0.12)
266266
f("-.12", -0.12)
267+
f("-1234.", -1234)
267268
f("12345.12345678901", 12345.12345678901)
268269
f("12345.123456789012", 12345.123456789012)
269270
f("12345.1234567890123", 12345.1234567890123)
@@ -417,6 +418,7 @@ func TestParseSuccess(t *testing.T) {
417418
f("12.", 12)
418419
f(".12", 0.12)
419420
f("-.12", -0.12)
421+
f("-1234.", -1234)
420422
f("12345.12345678901", 12345.12345678901)
421423
f("12345.123456789012", 12345.123456789012)
422424
f("12345.1234567890123", 12345.1234567890123)

0 commit comments

Comments
 (0)