Skip to content

Commit

Permalink
fastfloat: support elided integer or float part (#84)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
hagen1778 committed Dec 29, 2022
1 parent 6dae91c commit 6f52d1b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
32 changes: 28 additions & 4 deletions fastfloat/parse.go
Expand Up @@ -213,6 +213,10 @@ func ParseBestEffort(s string) float64 {
}
}

// the integer part might be elided to remain compliant
// with https://go.dev/ref/spec#Floating-point_literals
intPartElided := s[i] == '.'

d := uint64(0)
j := i
for i < uint(len(s)) {
Expand All @@ -232,7 +236,7 @@ func ParseBestEffort(s string) float64 {
}
break
}
if i <= j {
if i <= j && !intPartElided {
s = s[i:]
if strings.HasPrefix(s, "+") {
s = s[1:]
Expand Down Expand Up @@ -263,7 +267,12 @@ func ParseBestEffort(s string) float64 {
// Parse fractional part.
i++
if i >= uint(len(s)) {
return 0
if intPartElided {
return 0
}
// the fractional part may be elided to remain compliant
// with https://go.dev/ref/spec#Floating-point_literals
return f
}
k := i
for i < uint(len(s)) {
Expand Down Expand Up @@ -296,6 +305,9 @@ func ParseBestEffort(s string) float64 {
}
}
if s[i] == 'e' || s[i] == 'E' {
if intPartElided {
return 0
}
// Parse exponent part.
i++
if i >= uint(len(s)) {
Expand Down Expand Up @@ -363,6 +375,10 @@ func Parse(s string) (float64, error) {
}
}

// the integer part might be elided to remain compliant
// with https://go.dev/ref/spec#Floating-point_literals
intPartElided := s[i] == '.'

d := uint64(0)
j := i
for i < uint(len(s)) {
Expand All @@ -382,7 +398,7 @@ func Parse(s string) (float64, error) {
}
break
}
if i <= j {
if i <= j && !intPartElided {
ss := s[i:]
if strings.HasPrefix(ss, "+") {
ss = ss[1:]
Expand Down Expand Up @@ -413,7 +429,12 @@ func Parse(s string) (float64, error) {
// Parse fractional part.
i++
if i >= uint(len(s)) {
return 0, fmt.Errorf("cannot parse fractional part in %q", s)
if intPartElided {
return 0, fmt.Errorf("cannot parse integer or fractional part in %q", s)
}
// the fractional part might be elided to remain compliant
// with https://go.dev/ref/spec#Floating-point_literals
return f, nil
}
k := i
for i < uint(len(s)) {
Expand Down Expand Up @@ -446,6 +467,9 @@ func Parse(s string) (float64, error) {
}
}
if s[i] == 'e' || s[i] == 'E' {
if intPartElided {
return 0, fmt.Errorf("cannot parse integer part in %q", s)
}
// Parse exponent part.
i++
if i >= uint(len(s)) {
Expand Down
12 changes: 8 additions & 4 deletions fastfloat/parse_test.go
Expand Up @@ -206,6 +206,7 @@ func TestParseBestEffort(t *testing.T) {
f("-", 0)
f("--", 0)
f("-.", 0)
f(".", 0)
f("-.e", 0)
f("+112", 0)
f("++", 0)
Expand All @@ -214,7 +215,6 @@ func TestParseBestEffort(t *testing.T) {
f("-e12", 0)
f(".", 0)
f("..34", 0)
f("-.32", 0)
f("-.e3", 0)
f(".e+3", 0)

Expand All @@ -224,7 +224,6 @@ func TestParseBestEffort(t *testing.T) {
f("12.34.56", 0)
f("13e34.56", 0)
f("12.34e56e4", 0)
f("12.", 0)
f("123..45", 0)
f("123ee34", 0)
f("123e", 0)
Expand Down Expand Up @@ -262,6 +261,9 @@ func TestParseBestEffort(t *testing.T) {
f("-0.1", -0.1)
f("-0.123", -0.123)
f("1.66", 1.66)
f("12.", 12)
f(".12", 0.12)
f("-.12", -0.12)
f("12345.12345678901", 12345.12345678901)
f("12345.123456789012", 12345.123456789012)
f("12345.1234567890123", 12345.1234567890123)
Expand Down Expand Up @@ -338,6 +340,7 @@ func TestParseFailure(t *testing.T) {
f(" bar ")
f("-")
f("--")
f(".")
f("-.")
f("-.e")
f("+112")
Expand All @@ -347,7 +350,6 @@ func TestParseFailure(t *testing.T) {
f("-e12")
f(".")
f("..34")
f("-.32")
f("-.e3")
f(".e+3")

Expand All @@ -357,7 +359,6 @@ func TestParseFailure(t *testing.T) {
f("12.34.56")
f("13e34.56")
f("12.34e56e4")
f("12.")
f("123..45")
f("123ee34")
f("123e")
Expand Down Expand Up @@ -413,6 +414,9 @@ func TestParseSuccess(t *testing.T) {
f("-0.1", -0.1)
f("-0.123", -0.123)
f("1.66", 1.66)
f("12.", 12)
f(".12", 0.12)
f("-.12", -0.12)
f("12345.12345678901", 12345.12345678901)
f("12345.123456789012", 12345.123456789012)
f("12345.1234567890123", 12345.1234567890123)
Expand Down

0 comments on commit 6f52d1b

Please sign in to comment.