Commit graph

2 commits

Author SHA1 Message Date
Russ Cox
1ff59f3dd3 strconv: clean up powers-of-10 table, tests
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>
2025-10-22 13:50:44 -07:00
Martin Möhrmann
63c4284346 strconv: check bitsize range in ParseInt and ParseUint
Return an error when a bitSize below 0 or above 64 is specified.

Move bitSize 0 handling in ParseInt after the call to ParseUint
to avoid a spill.

AMD64:
name       old time/op  new time/op  delta
Atoi       28.9ns ± 6%  27.4ns ± 6%  -5.21%  (p=0.002 n=20+20)
AtoiNeg    24.6ns ± 2%  23.1ns ± 1%  -6.04%  (p=0.000 n=19+18)
Atoi64     38.8ns ± 1%  38.0ns ± 1%  -2.03%  (p=0.000 n=17+20)
Atoi64Neg  35.5ns ± 1%  34.3ns ± 1%  -3.42%  (p=0.000 n=19+20)

Updates #21275

Change-Id: I70f0e4a16fa003f7ea929ca4ef56bd1a4181660b
Reviewed-on: https://go-review.googlesource.com/55139
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
2017-08-22 13:37:40 +00:00