aboutsummaryrefslogtreecommitdiff
path: root/src/strconv/eisel_lemire.go
AgeCommit message (Collapse)Author
2025-10-29strconv: move all but Quote to internal/strconvRuss Cox
This will let low-level things depend on the canonical routines, even for floating-point printing. Change-Id: I31207dc6584ad90d4e365dbe6eaf20f8662ed22d Reviewed-on: https://go-review.googlesource.com/c/go/+/716000 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-22strconv: clean up powers-of-10 table, testsRuss Cox
Both Eisel-Lemire and Ryu depend on a table of truncated 128-bit mantissas of powers of 10, and so will Dragonbox. This CL: - Moves the table to a separate file, so it doesn't look tied to Eisel-Lemire. - Introduces a uint128 type in math.go for the table values, since .Hi and .Lo are clearer than [1] and [0]. - Generates the table from a standalone generator pow10gen.go. - Adds a new pow10 function in math.go to handle table access details. - Factors a 64x128->192-bit multiply into umul192 in math.go. - Moves multiplication by log₁₀ 2 and log₂ 10 into math.go. - Introduces an import_test.go to avoid having to type differently cased names in test code versus regular code. - Introduces named constants for the floating-point size parameters. Previously these were only in the floatInfo global variables. - Changes the BenchmarkAppendUintVarlen subtest names to be more useful. Change-Id: I9826ee5f41c5c19be3b6a7c3c5f277ec6c23b39a Reviewed-on: https://go-review.googlesource.com/c/go/+/712661 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-24[dev.regabi] strconv: add to bootstrap packagesMatthew Dempsky
go/constant relies on strconv for parsing Go literals, while older versions of strconv either lack recent Go language features (e.g., Go 1.13's new numeric literals) or have errors (e.g., mishandling of carriage returns in raw string literals prior to Go 1.8). This requires two changes: 1. Splitting out the internal/bytealg dependency into a separate file, which can be easily substituted with a simple loop for bootstrap builds. 2. Updating eisel_lemire.go to not utilize Go 1.13 functionality (underscores in numeric literals and signed shift counts). Change-Id: Ib48a858a03b155eebdcd08d577aec2254337e70e Reviewed-on: https://go-review.googlesource.com/c/go/+/272749 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
2020-10-23strconv: add eiselLemire32Nigel Tao
This does for ParseFloat(etc, 32) what commit a2eb53c571 did for ParseFloat(etc, 64). name old time/op new time/op delta Atof32Decimal-4 48.3ns ± 4% 48.8ns ± 2% ~ (p=0.548 n=5+5) Atof32Float-4 56.2ns ± 5% 54.7ns ± 3% ~ (p=0.246 n=5+5) Atof32FloatExp-4 104ns ± 0% 76ns ± 2% -27.19% (p=0.008 n=5+5) Atof32Random-4 142ns ± 2% 109ns ± 1% -23.07% (p=0.008 n=5+5) Change-Id: I6ee5a2f2d791d4fe3028f1d40aca96400120fda0 Reviewed-on: https://go-review.googlesource.com/c/go/+/264517 Trust: Nigel Tao <nigeltao@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-22strconv: increase the Eisel-Lemire exp10 rangeNigel Tao
This grows the exp10 range for which the Eisel-Lemire algorithm applies from [-307, +288] to [-348, +347], roughly equivalent to the existing powersOfTen table in extfloat.go (which uses a different algorithm). name old time/op new time/op delta Atof64Decimal-4 48.4ns ± 1% 48.7ns ± 3% ~ (p=0.698 n=5+5) Atof64Float-4 57.9ns ± 1% 58.1ns ± 2% ~ (p=0.873 n=5+5) Atof64FloatExp-4 71.8ns ± 2% 72.2ns ± 2% ~ (p=0.730 n=5+5) Atof64Big-4 165ns ± 1% 164ns ± 1% ~ (p=0.635 n=5+5) Atof64RandomBits-4 165ns ± 1% 165ns ± 6% ~ (p=0.143 n=5+5) Atof64RandomFloats-4 147ns ± 2% 147ns ± 1% ~ (p=0.857 n=5+5) Change-Id: Idf7dc5297db6db2bd9e0bd4cb0e55e021916fa43 Reviewed-on: https://go-review.googlesource.com/c/go/+/264139 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Nigel Tao <nigeltao@golang.org>
2020-10-22strconv: fix Eisel-Lemire for negative zeroNigel Tao
This is somewhat academic (and no tests failed before this commit), since func atof64 only calls func eiselLemire when func atof64exact fails, and func atof64exact doesn't fail when parsing positive or negative zeroes. But it's still worth fixing. Change-Id: Ibe6ef4c8fd96827673b711d5456003fbc447e39c Reviewed-on: https://go-review.googlesource.com/c/go/+/264140 Trust: Nigel Tao <nigeltao@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-17strconv: use the Eisel-Lemire ParseFloat algorithmNigel Tao
Also fix BenchmarkAtof64Random* to initialize the test data when none of the TestAtof* tests are run. Passing "go test -test.count=5 -test.run=xxx -test.bench=Atof64" on to benchstat: name old time/op new time/op delta Atof64Decimal-4 47.9ns ± 0% 48.3ns ± 1% ~ (p=0.238 n=4+5) Atof64Float-4 58.3ns ± 3% 57.7ns ± 0% ~ (p=0.151 n=5+5) Atof64FloatExp-4 107ns ± 0% 71ns ± 1% -33.89% (p=0.016 n=4+5) Atof64Big-4 163ns ± 0% 166ns ± 2% ~ (p=0.159 n=4+5) Atof64RandomBits-4 299ns ± 1% 166ns ± 1% -44.41% (p=0.008 n=5+5) Atof64RandomFloats-4 188ns ± 1% 144ns ± 0% -23.03% (p=0.008 n=5+5) The canada.json file from github.com/miloyip/nativejson-benchmark is full of geospatial coordinates (i.e. numbers). With this program: src, _ := ioutil.ReadFile("canada.json") for i := 0; i < 5; i++ { now := time.Now() for j := 0; j < 10; j++ { dst := interface{}(nil) if err := json.Unmarshal(src, &dst); err != nil { log.Fatal(err) } } fmt.Println(time.Since(now)) } Median of the 5 printed numbers, lower is better. Before: 760.819549ms After: 702.651646ms Ratio: 1.08x The new detailedPowersOfTen table weighs in at 596 * 16 = 9536 bytes, but some of that weight gain can be clawed back, in a follow-up commit, that folds in the existing powersOfTen table in extfloat.go. RELNOTE=yes Change-Id: I3953110deaa1f5f6941e88e8417c4665b649ed80 Reviewed-on: https://go-review.googlesource.com/c/go/+/260858 Run-TryBot: Nigel Tao <nigeltao@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Nigel Tao <nigeltao@golang.org>