Skip to content

Commit 6f52d1b

Browse files
authored
fastfloat: support elided integer or float part (valyala#84)
One of the integer part or the fractional part may be elided; one of the decimal point or the exponent part may be elided. According to https://go.dev/ref/spec#Floating-point_literals Relevant issue: VictoriaMetrics/VictoriaMetrics#3544 benchstat: ``` benchstat old.txt new.txt name old time/op new time/op delta ParseUint64/0/std-10 0.50ns ± 0% 0.52ns ± 1% ~ (p=0.100 n=3+3) ParseUint64/0/custom-10 0.31ns ± 0% 0.33ns ± 3% ~ (p=0.100 n=3+3) ParseUint64/12/std-10 0.70ns ± 0% 0.71ns ± 0% ~ (p=0.100 n=3+3) ParseUint64/12/custom-10 0.47ns ± 1% 0.47ns ± 1% ~ (p=0.100 n=3+3) ParseUint64/12345/std-10 1.05ns ± 1% 1.07ns ± 0% ~ (p=0.100 n=3+3) ParseUint64/12345/custom-10 0.84ns ± 0% 0.86ns ± 1% ~ (p=0.100 n=3+3) ParseUint64/1234567890/std-10 1.66ns ± 1% 1.68ns ± 0% ~ (p=0.600 n=3+3) ParseUint64/1234567890/custom-10 1.24ns ± 0% 1.26ns ± 1% ~ (p=0.200 n=3+3) ParseUint64/9223372036854775807/std-10 2.87ns ± 0% 2.87ns ± 0% ~ (p=1.000 n=3+3) ParseUint64/9223372036854775807/custom-10 4.67ns ± 0% 4.68ns ± 0% ~ (p=0.700 n=3+3) ParseUint64BestEffort/0/std-10 0.51ns ± 1% 0.51ns ± 1% ~ (p=1.000 n=3+3) ParseUint64BestEffort/0/custom-10 0.31ns ± 1% 0.31ns ± 1% ~ (p=1.000 n=3+3) ParseUint64BestEffort/12/std-10 0.69ns ± 0% 0.70ns ± 1% ~ (p=0.700 n=3+3) ParseUint64BestEffort/12/custom-10 0.46ns ± 0% 0.46ns ± 0% ~ (p=0.100 n=3+3) ParseUint64BestEffort/12345/std-10 1.05ns ± 0% 1.06ns ± 1% ~ (p=0.200 n=3+3) ParseUint64BestEffort/12345/custom-10 0.84ns ± 1% 0.84ns ± 0% ~ (p=1.000 n=3+3) ParseUint64BestEffort/1234567890/std-10 1.65ns ± 0% 1.66ns ± 0% ~ (p=0.700 n=3+3) ParseUint64BestEffort/1234567890/custom-10 1.25ns ± 2% 1.24ns ± 0% ~ (p=1.000 n=3+3) ParseUint64BestEffort/9223372036854775807/std-10 2.88ns ± 0% 2.88ns ± 0% ~ (p=0.300 n=3+3) ParseUint64BestEffort/9223372036854775807/custom-10 4.66ns ± 1% 4.66ns ± 0% ~ (p=0.700 n=3+3) ParseInt64/0/std-10 0.81ns ± 0% 0.79ns ± 2% ~ (p=0.100 n=3+3) ParseInt64/0/custom-10 0.35ns ± 0% 0.35ns ± 0% ~ (p=0.800 n=3+3) ParseInt64/12/std-10 1.01ns ± 0% 0.97ns ± 0% ~ (p=0.100 n=3+3) ParseInt64/12/custom-10 0.51ns ± 0% 0.51ns ± 0% ~ (p=0.600 n=3+3) ParseInt64/12345/std-10 1.37ns ± 1% 1.32ns ± 0% ~ (p=0.100 n=3+3) ParseInt64/12345/custom-10 0.90ns ± 2% 0.89ns ± 0% ~ (p=0.700 n=3+3) ParseInt64/1234567890/std-10 1.94ns ± 0% 1.95ns ± 0% ~ (p=0.200 n=3+3) ParseInt64/1234567890/custom-10 1.28ns ± 0% 1.28ns ± 0% ~ (p=1.000 n=3+3) ParseInt64/9223372036854775807/std-10 3.18ns ± 0% 3.18ns ± 0% ~ (p=1.000 n=3+3) ParseInt64/9223372036854775807/custom-10 4.84ns ± 0% 4.86ns ± 1% ~ (p=0.200 n=3+3) ParseInt64BestEffort/0/std-10 0.78ns ± 0% 0.78ns ± 0% ~ (p=0.700 n=3+3) ParseInt64BestEffort/0/custom-10 0.35ns ± 0% 0.35ns ± 2% ~ (p=0.400 n=3+3) ParseInt64BestEffort/12/std-10 0.97ns ± 0% 0.97ns ± 0% ~ (p=0.100 n=3+3) ParseInt64BestEffort/12/custom-10 0.51ns ± 2% 0.50ns ± 0% ~ (p=0.200 n=3+3) ParseInt64BestEffort/12345/std-10 1.33ns ± 0% 1.33ns ± 1% ~ (p=0.600 n=3+3) ParseInt64BestEffort/12345/custom-10 0.88ns ± 1% 0.89ns ± 0% ~ (p=0.200 n=3+3) ParseInt64BestEffort/1234567890/std-10 1.96ns ± 1% 1.95ns ± 0% ~ (p=0.400 n=3+3) ParseInt64BestEffort/1234567890/custom-10 1.27ns ± 1% 1.27ns ± 1% ~ (p=1.000 n=3+3) ParseInt64BestEffort/9223372036854775807/std-10 3.18ns ± 0% 3.20ns ± 1% ~ (p=0.200 n=3+3) ParseInt64BestEffort/9223372036854775807/custom-10 4.93ns ± 1% 4.92ns ± 0% ~ (p=0.800 n=3+3) ParseBestEffort/0/std-10 1.42ns ± 1% 1.41ns ± 1% ~ (p=0.400 n=3+3) ParseBestEffort/0/custom-10 0.42ns ± 0% 0.43ns ± 1% ~ (p=0.400 n=3+3) ParseBestEffort/12/std-10 1.76ns ± 1% 1.75ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12/custom-10 0.54ns ± 0% 0.55ns ± 1% ~ (p=0.200 n=3+3) ParseBestEffort/12345/std-10 2.35ns ± 1% 2.34ns ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/12345/custom-10 0.91ns ± 0% 0.70ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234567890/std-10 3.38ns ± 1% 3.38ns ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/1234567890/custom-10 1.32ns ± 2% 1.09ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234.45678/std-10 3.27ns ± 1% 3.29ns ± 1% ~ (p=0.800 n=3+3) ParseBestEffort/1234.45678/custom-10 1.56ns ± 2% 1.30ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234e45/std-10 2.83ns ± 1% 2.82ns ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/1234e45/custom-10 1.31ns ± 2% 1.06ns ± 1% ~ (p=0.100 n=3+3) ParseBestEffort/12.34e-34/std-10 2.97ns ± 0% 2.97ns ± 0% ~ (p=0.700 n=3+3) ParseBestEffort/12.34e-34/custom-10 1.33ns ± 0% 1.28ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12345.1234567890/std-10 4.48ns ± 0% 4.53ns ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12345.1234567890/custom-10 2.03ns ± 0% 1.76ns ± 1% ~ (p=0.100 n=3+3) ParseBestEffort/12345.12345678901/std-10 4.68ns ± 0% 4.70ns ± 0% ~ (p=0.400 n=3+3) ParseBestEffort/12345.12345678901/custom-10 6.46ns ± 1% 6.14ns ± 0% ~ (p=0.100 n=3+3) Parse/0/std-10 1.41ns ± 0% 1.43ns ± 1% ~ (p=0.200 n=3+3) Parse/0/custom-10 0.42ns ± 0% 0.46ns ± 1% ~ (p=0.100 n=3+3) Parse/12/std-10 1.75ns ± 0% 1.77ns ± 2% ~ (p=0.800 n=3+3) Parse/12/custom-10 0.51ns ± 1% 0.61ns ± 0% ~ (p=0.100 n=3+3) Parse/12345/std-10 2.34ns ± 0% 2.34ns ± 0% ~ (p=1.000 n=3+3) Parse/12345/custom-10 0.67ns ± 0% 0.99ns ± 0% ~ (p=0.100 n=3+3) Parse/1234567890/std-10 3.44ns ± 4% 3.39ns ± 0% ~ (p=1.000 n=3+3) Parse/1234567890/custom-10 1.07ns ± 1% 1.38ns ± 0% ~ (p=0.100 n=3+3) Parse/1234.45678/std-10 3.29ns ± 2% 3.27ns ± 0% ~ (p=1.000 n=3+3) Parse/1234.45678/custom-10 1.26ns ± 0% 1.58ns ± 0% ~ (p=0.100 n=3+3) Parse/1234e45/std-10 2.82ns ± 0% 2.83ns ± 0% ~ (p=0.100 n=3+3) Parse/1234e45/custom-10 1.06ns ± 0% 1.39ns ± 1% ~ (p=0.100 n=3+3) Parse/12.34e-34/std-10 2.98ns ± 0% 2.99ns ± 0% ~ (p=0.400 n=3+3) Parse/12.34e-34/custom-10 1.29ns ± 0% 1.37ns ± 0% ~ (p=0.100 n=3+3) Parse/12345.1234567890/std-10 4.64ns ± 4% 4.50ns ± 1% ~ (p=0.200 n=3+3) Parse/12345.1234567890/custom-10 1.79ns ± 2% 2.06ns ± 0% ~ (p=0.100 n=3+3) Parse/12345.12345678901/std-10 4.71ns ± 1% 4.70ns ± 1% ~ (p=0.700 n=3+3) Parse/12345.12345678901/custom-10 6.22ns ± 1% 6.47ns ± 1% ~ (p=0.100 n=3+3) name old speed new speed delta ParseUint64/0/std-10 1.99GB/s ± 0% 1.93GB/s ± 1% ~ (p=0.100 n=3+3) ParseUint64/0/custom-10 3.18GB/s ± 0% 3.06GB/s ± 3% ~ (p=0.100 n=3+3) ParseUint64/12/std-10 2.87GB/s ± 0% 2.82GB/s ± 0% ~ (p=0.100 n=3+3) ParseUint64/12/custom-10 4.30GB/s ± 1% 4.22GB/s ± 1% ~ (p=0.100 n=3+3) ParseUint64/12345/std-10 4.76GB/s ± 1% 4.67GB/s ± 0% ~ (p=0.100 n=3+3) ParseUint64/12345/custom-10 5.94GB/s ± 0% 5.78GB/s ± 1% ~ (p=0.100 n=3+3) ParseUint64/1234567890/std-10 6.02GB/s ± 1% 5.94GB/s ± 0% ~ (p=0.700 n=3+3) ParseUint64/1234567890/custom-10 8.06GB/s ± 0% 7.96GB/s ± 1% ~ (p=0.200 n=3+3) ParseUint64/9223372036854775807/std-10 6.61GB/s ± 0% 6.61GB/s ± 0% ~ (p=1.000 n=3+3) ParseUint64/9223372036854775807/custom-10 4.07GB/s ± 0% 4.06GB/s ± 0% ~ (p=0.700 n=3+3) ParseUint64BestEffort/0/std-10 1.98GB/s ± 1% 1.98GB/s ± 1% ~ (p=1.000 n=3+3) ParseUint64BestEffort/0/custom-10 3.18GB/s ± 1% 3.18GB/s ± 1% ~ (p=1.000 n=3+3) ParseUint64BestEffort/12/std-10 2.88GB/s ± 0% 2.87GB/s ± 1% ~ (p=0.700 n=3+3) ParseUint64BestEffort/12/custom-10 4.35GB/s ± 0% 4.34GB/s ± 0% ~ (p=0.100 n=3+3) ParseUint64BestEffort/12345/std-10 4.78GB/s ± 0% 4.71GB/s ± 1% ~ (p=0.100 n=3+3) ParseUint64BestEffort/12345/custom-10 5.96GB/s ± 1% 5.96GB/s ± 0% ~ (p=1.000 n=3+3) ParseUint64BestEffort/1234567890/std-10 6.06GB/s ± 0% 6.04GB/s ± 0% ~ (p=0.700 n=3+3) ParseUint64BestEffort/1234567890/custom-10 8.02GB/s ± 2% 8.07GB/s ± 0% ~ (p=1.000 n=3+3) ParseUint64BestEffort/9223372036854775807/std-10 6.60GB/s ± 0% 6.59GB/s ± 0% ~ (p=0.200 n=3+3) ParseUint64BestEffort/9223372036854775807/custom-10 4.07GB/s ± 1% 4.08GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64/0/std-10 1.23GB/s ± 0% 1.26GB/s ± 2% ~ (p=0.100 n=3+3) ParseInt64/0/custom-10 2.84GB/s ± 0% 2.84GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64/12/std-10 1.98GB/s ± 0% 2.07GB/s ± 0% ~ (p=0.100 n=3+3) ParseInt64/12/custom-10 3.93GB/s ± 0% 3.93GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64/12345/std-10 3.66GB/s ± 1% 3.78GB/s ± 0% ~ (p=0.100 n=3+3) ParseInt64/12345/custom-10 5.54GB/s ± 2% 5.62GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64/1234567890/std-10 5.15GB/s ± 0% 5.13GB/s ± 0% ~ (p=0.200 n=3+3) ParseInt64/1234567890/custom-10 7.81GB/s ± 0% 7.82GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64/9223372036854775807/std-10 5.98GB/s ± 0% 5.98GB/s ± 0% ~ (p=1.000 n=3+3) ParseInt64/9223372036854775807/custom-10 3.93GB/s ± 0% 3.91GB/s ± 1% ~ (p=0.200 n=3+3) ParseInt64BestEffort/0/std-10 1.29GB/s ± 0% 1.28GB/s ± 0% ~ (p=0.700 n=3+3) ParseInt64BestEffort/0/custom-10 2.86GB/s ± 0% 2.83GB/s ± 2% ~ (p=0.400 n=3+3) ParseInt64BestEffort/12/std-10 2.07GB/s ± 0% 2.06GB/s ± 0% ~ (p=0.100 n=3+3) ParseInt64BestEffort/12/custom-10 3.94GB/s ± 2% 4.00GB/s ± 0% ~ (p=0.200 n=3+3) ParseInt64BestEffort/12345/std-10 3.77GB/s ± 0% 3.77GB/s ± 1% ~ (p=0.700 n=3+3) ParseInt64BestEffort/12345/custom-10 5.68GB/s ± 1% 5.65GB/s ± 0% ~ (p=0.200 n=3+3) ParseInt64BestEffort/1234567890/std-10 5.11GB/s ± 1% 5.14GB/s ± 0% ~ (p=0.400 n=3+3) ParseInt64BestEffort/1234567890/custom-10 7.86GB/s ± 1% 7.85GB/s ± 1% ~ (p=1.000 n=3+3) ParseInt64BestEffort/9223372036854775807/std-10 5.98GB/s ± 0% 5.94GB/s ± 1% ~ (p=0.100 n=3+3) ParseInt64BestEffort/9223372036854775807/custom-10 3.85GB/s ± 1% 3.87GB/s ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/0/std-10 705MB/s ± 1% 709MB/s ± 1% ~ (p=0.400 n=3+3) ParseBestEffort/0/custom-10 2.37GB/s ± 0% 2.35GB/s ± 1% ~ (p=0.400 n=3+3) ParseBestEffort/12/std-10 1.13GB/s ± 1% 1.14GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12/custom-10 3.71GB/s ± 0% 3.67GB/s ± 1% ~ (p=0.200 n=3+3) ParseBestEffort/12345/std-10 2.13GB/s ± 1% 2.13GB/s ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/12345/custom-10 5.50GB/s ± 0% 7.10GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234567890/std-10 2.96GB/s ± 0% 2.96GB/s ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/1234567890/custom-10 7.56GB/s ± 2% 9.14GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234.45678/std-10 3.06GB/s ± 1% 3.04GB/s ± 1% ~ (p=0.700 n=3+3) ParseBestEffort/1234.45678/custom-10 6.41GB/s ± 2% 7.71GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/1234e45/std-10 2.48GB/s ± 1% 2.48GB/s ± 0% ~ (p=1.000 n=3+3) ParseBestEffort/1234e45/custom-10 5.33GB/s ± 2% 6.59GB/s ± 1% ~ (p=0.100 n=3+3) ParseBestEffort/12.34e-34/std-10 3.03GB/s ± 0% 3.03GB/s ± 0% ~ (p=0.700 n=3+3) ParseBestEffort/12.34e-34/custom-10 6.75GB/s ± 0% 7.04GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12345.1234567890/std-10 3.57GB/s ± 0% 3.54GB/s ± 0% ~ (p=0.100 n=3+3) ParseBestEffort/12345.1234567890/custom-10 7.89GB/s ± 0% 9.07GB/s ± 1% ~ (p=0.100 n=3+3) ParseBestEffort/12345.12345678901/std-10 3.63GB/s ± 0% 3.61GB/s ± 0% ~ (p=0.400 n=3+3) ParseBestEffort/12345.12345678901/custom-10 2.63GB/s ± 1% 2.77GB/s ± 0% ~ (p=0.100 n=3+3) Parse/0/std-10 709MB/s ± 0% 700MB/s ± 1% ~ (p=0.200 n=3+3) Parse/0/custom-10 2.36GB/s ± 0% 2.17GB/s ± 1% ~ (p=0.100 n=3+3) Parse/12/std-10 1.14GB/s ± 0% 1.13GB/s ± 2% ~ (p=1.000 n=3+3) Parse/12/custom-10 3.95GB/s ± 1% 3.26GB/s ± 0% ~ (p=0.100 n=3+3) Parse/12345/std-10 2.13GB/s ± 0% 2.14GB/s ± 0% ~ (p=1.000 n=3+3) Parse/12345/custom-10 7.47GB/s ± 0% 5.04GB/s ± 0% ~ (p=0.100 n=3+3) Parse/1234567890/std-10 2.91GB/s ± 4% 2.95GB/s ± 0% ~ (p=1.000 n=3+3) Parse/1234567890/custom-10 9.36GB/s ± 1% 7.25GB/s ± 0% ~ (p=0.100 n=3+3) Parse/1234.45678/std-10 3.04GB/s ± 2% 3.06GB/s ± 0% ~ (p=1.000 n=3+3) Parse/1234.45678/custom-10 7.95GB/s ± 0% 6.31GB/s ± 0% ~ (p=0.100 n=3+3) Parse/1234e45/std-10 2.48GB/s ± 0% 2.47GB/s ± 0% ~ (p=0.100 n=3+3) Parse/1234e45/custom-10 6.63GB/s ± 0% 5.04GB/s ± 1% ~ (p=0.100 n=3+3) Parse/12.34e-34/std-10 3.02GB/s ± 0% 3.01GB/s ± 0% ~ (p=0.400 n=3+3) Parse/12.34e-34/custom-10 6.99GB/s ± 0% 6.59GB/s ± 0% ~ (p=0.100 n=3+3) Parse/12345.1234567890/std-10 3.45GB/s ± 4% 3.55GB/s ± 1% ~ (p=0.200 n=3+3) Parse/12345.1234567890/custom-10 8.95GB/s ± 2% 7.77GB/s ± 0% ~ (p=0.100 n=3+3) Parse/12345.12345678901/std-10 3.61GB/s ± 1% 3.62GB/s ± 1% ~ (p=0.700 n=3+3) Parse/12345.12345678901/custom-10 2.74GB/s ± 1% 2.63GB/s ± 1% ~ (p=0.100 n=3+3) ```
1 parent 6dae91c commit 6f52d1b

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

fastfloat/parse.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ func ParseBestEffort(s string) float64 {
213213
}
214214
}
215215

216+
// the integer part might be elided to remain compliant
217+
// with https://go.dev/ref/spec#Floating-point_literals
218+
intPartElided := s[i] == '.'
219+
216220
d := uint64(0)
217221
j := i
218222
for i < uint(len(s)) {
@@ -232,7 +236,7 @@ func ParseBestEffort(s string) float64 {
232236
}
233237
break
234238
}
235-
if i <= j {
239+
if i <= j && !intPartElided {
236240
s = s[i:]
237241
if strings.HasPrefix(s, "+") {
238242
s = s[1:]
@@ -263,7 +267,12 @@ func ParseBestEffort(s string) float64 {
263267
// Parse fractional part.
264268
i++
265269
if i >= uint(len(s)) {
266-
return 0
270+
if intPartElided {
271+
return 0
272+
}
273+
// the fractional part may be elided to remain compliant
274+
// with https://go.dev/ref/spec#Floating-point_literals
275+
return f
267276
}
268277
k := i
269278
for i < uint(len(s)) {
@@ -296,6 +305,9 @@ func ParseBestEffort(s string) float64 {
296305
}
297306
}
298307
if s[i] == 'e' || s[i] == 'E' {
308+
if intPartElided {
309+
return 0
310+
}
299311
// Parse exponent part.
300312
i++
301313
if i >= uint(len(s)) {
@@ -363,6 +375,10 @@ func Parse(s string) (float64, error) {
363375
}
364376
}
365377

378+
// the integer part might be elided to remain compliant
379+
// with https://go.dev/ref/spec#Floating-point_literals
380+
intPartElided := s[i] == '.'
381+
366382
d := uint64(0)
367383
j := i
368384
for i < uint(len(s)) {
@@ -382,7 +398,7 @@ func Parse(s string) (float64, error) {
382398
}
383399
break
384400
}
385-
if i <= j {
401+
if i <= j && !intPartElided {
386402
ss := s[i:]
387403
if strings.HasPrefix(ss, "+") {
388404
ss = ss[1:]
@@ -413,7 +429,12 @@ func Parse(s string) (float64, error) {
413429
// Parse fractional part.
414430
i++
415431
if i >= uint(len(s)) {
416-
return 0, fmt.Errorf("cannot parse fractional part in %q", s)
432+
if intPartElided {
433+
return 0, fmt.Errorf("cannot parse integer or fractional part in %q", s)
434+
}
435+
// the fractional part might be elided to remain compliant
436+
// with https://go.dev/ref/spec#Floating-point_literals
437+
return f, nil
417438
}
418439
k := i
419440
for i < uint(len(s)) {
@@ -446,6 +467,9 @@ func Parse(s string) (float64, error) {
446467
}
447468
}
448469
if s[i] == 'e' || s[i] == 'E' {
470+
if intPartElided {
471+
return 0, fmt.Errorf("cannot parse integer part in %q", s)
472+
}
449473
// Parse exponent part.
450474
i++
451475
if i >= uint(len(s)) {

fastfloat/parse_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func TestParseBestEffort(t *testing.T) {
206206
f("-", 0)
207207
f("--", 0)
208208
f("-.", 0)
209+
f(".", 0)
209210
f("-.e", 0)
210211
f("+112", 0)
211212
f("++", 0)
@@ -214,7 +215,6 @@ func TestParseBestEffort(t *testing.T) {
214215
f("-e12", 0)
215216
f(".", 0)
216217
f("..34", 0)
217-
f("-.32", 0)
218218
f("-.e3", 0)
219219
f(".e+3", 0)
220220

@@ -224,7 +224,6 @@ func TestParseBestEffort(t *testing.T) {
224224
f("12.34.56", 0)
225225
f("13e34.56", 0)
226226
f("12.34e56e4", 0)
227-
f("12.", 0)
228227
f("123..45", 0)
229228
f("123ee34", 0)
230229
f("123e", 0)
@@ -262,6 +261,9 @@ func TestParseBestEffort(t *testing.T) {
262261
f("-0.1", -0.1)
263262
f("-0.123", -0.123)
264263
f("1.66", 1.66)
264+
f("12.", 12)
265+
f(".12", 0.12)
266+
f("-.12", -0.12)
265267
f("12345.12345678901", 12345.12345678901)
266268
f("12345.123456789012", 12345.123456789012)
267269
f("12345.1234567890123", 12345.1234567890123)
@@ -338,6 +340,7 @@ func TestParseFailure(t *testing.T) {
338340
f(" bar ")
339341
f("-")
340342
f("--")
343+
f(".")
341344
f("-.")
342345
f("-.e")
343346
f("+112")
@@ -347,7 +350,6 @@ func TestParseFailure(t *testing.T) {
347350
f("-e12")
348351
f(".")
349352
f("..34")
350-
f("-.32")
351353
f("-.e3")
352354
f(".e+3")
353355

@@ -357,7 +359,6 @@ func TestParseFailure(t *testing.T) {
357359
f("12.34.56")
358360
f("13e34.56")
359361
f("12.34e56e4")
360-
f("12.")
361362
f("123..45")
362363
f("123ee34")
363364
f("123e")
@@ -413,6 +414,9 @@ func TestParseSuccess(t *testing.T) {
413414
f("-0.1", -0.1)
414415
f("-0.123", -0.123)
415416
f("1.66", 1.66)
417+
f("12.", 12)
418+
f(".12", 0.12)
419+
f("-.12", -0.12)
416420
f("12345.12345678901", 12345.12345678901)
417421
f("12345.123456789012", 12345.123456789012)
418422
f("12345.1234567890123", 12345.1234567890123)

0 commit comments

Comments
 (0)