1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:36:27 -07:00
go/src/strconv
Rémy Oudompheng 61a08fc6ce strconv: Implement Ryū algorithm for ftoa shortest mode
This patch implements the algorithm from Ulf Adams,
"Ryū: Fast Float-to-String Conversion" (doi:10.1145/3192366.3192369)
for formatting floating-point numbers with a fixed number of decimal
digits.

It is not a direct translation of the reference C implementation
but still follows the original paper. In particular, it uses full
128-bit powers of 10, which allows for more precision in the other
modes (fixed ftoa, atof).

name                              old time/op  new time/op   delta
AppendFloat/Decimal-4             49.6ns ± 3%   59.3ns ± 0%  +19.59%  (p=0.008 n=5+5)
AppendFloat/Float-4                122ns ± 1%     91ns ± 1%  -25.92%  (p=0.008 n=5+5)
AppendFloat/Exp-4                 89.3ns ± 1%  100.0ns ± 1%  +11.98%  (p=0.008 n=5+5)
AppendFloat/NegExp-4              88.3ns ± 2%   97.1ns ± 1%   +9.87%  (p=0.008 n=5+5)
AppendFloat/LongExp-4              143ns ± 2%    103ns ± 0%  -28.17%  (p=0.016 n=5+4)
AppendFloat/Big-4                  144ns ± 1%    110ns ± 1%  -23.26%  (p=0.008 n=5+5)
AppendFloat/BinaryExp-4           46.2ns ± 2%   46.0ns ± 1%     ~     (p=0.603 n=5+5)
AppendFloat/32Integer-4           49.1ns ± 1%   58.7ns ± 1%  +19.57%  (p=0.008 n=5+5)
AppendFloat/32ExactFraction-4     95.6ns ± 1%   88.6ns ± 1%   -7.30%  (p=0.008 n=5+5)
AppendFloat/32Point-4              122ns ± 1%     87ns ± 1%  -28.63%  (p=0.008 n=5+5)
AppendFloat/32Exp-4               88.6ns ± 2%   95.0ns ± 1%   +7.29%  (p=0.008 n=5+5)
AppendFloat/32NegExp-4            87.2ns ± 1%   91.3ns ± 1%   +4.63%  (p=0.008 n=5+5)
AppendFloat/32Shortest-4           107ns ± 1%     82ns ± 0%  -24.08%  (p=0.008 n=5+5)
AppendFloat/Slowpath64-4          1.00µs ± 1%   0.10µs ± 0%  -89.92%  (p=0.016 n=5+4)
AppendFloat/SlowpathDenormal64-4  34.1µs ± 3%    0.1µs ± 1%  -99.72%  (p=0.008 n=5+5)

Fixes #15672

Change-Id: Ib90dfa245f62490a6666671896013cf3f9a1fb22
Reviewed-on: https://go-review.googlesource.com/c/go/+/170080
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2021-04-15 09:18:03 +00:00
..
testdata
atob_test.go
atob.go
atoc_test.go strconv: revert ParseFloat/ParseComplex error on incorrect bitSize 2020-11-03 23:05:51 +00:00
atoc.go strconv: revert ParseFloat/ParseComplex error on incorrect bitSize 2020-11-03 23:05:51 +00:00
atof_test.go strconv: revert ParseFloat/ParseComplex error on incorrect bitSize 2020-11-03 23:05:51 +00:00
atof.go strconv: revert ParseFloat/ParseComplex error on incorrect bitSize 2020-11-03 23:05:51 +00:00
atoi_test.go
atoi.go strconv: add ParseComplex and FormatComplex 2020-05-08 17:31:38 +00:00
bytealg_bootstrap.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
bytealg.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
ctoa_test.go strconv: fix incorrect bit size in ParseComplex; add tests 2020-10-30 00:13:25 +00:00
ctoa.go strconv: add ParseComplex and FormatComplex 2020-05-08 17:31:38 +00:00
decimal_test.go
decimal.go
doc.go
eisel_lemire.go [dev.regabi] strconv: add to bootstrap packages 2020-11-24 19:42:42 +00:00
example_test.go
export_test.go
extfloat.go strconv: remove extfloat.go atof code path 2020-10-29 03:06:12 +00:00
fp_test.go
ftoa_test.go strconv: Implement Ryū algorithm for ftoa shortest mode 2021-04-15 09:18:03 +00:00
ftoa.go strconv: Implement Ryū algorithm for ftoa shortest mode 2021-04-15 09:18:03 +00:00
ftoaryu_test.go strconv: implement Ryū-like algorithm for fixed precision ftoa 2021-04-15 08:44:21 +00:00
ftoaryu.go strconv: Implement Ryū algorithm for ftoa shortest mode 2021-04-15 09:18:03 +00:00
internal_test.go strconv: implement Ryū-like algorithm for fixed precision ftoa 2021-04-15 08:44:21 +00:00
isprint.go unicode: upgrade to Unicode 13.0.0 2020-08-20 13:41:13 +00:00
itoa_test.go
itoa.go
makeisprint.go all: faster midpoint computation in binary search 2021-02-23 01:37:31 +00:00
quote_test.go
quote.go all: faster midpoint computation in binary search 2021-02-23 01:37:31 +00:00
strconv_test.go