summaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorBen Hoyt <benhoyt@gmail.com>2022-06-04 18:31:40 +1200
committerGopher Robot <gobot@golang.org>2022-06-04 21:18:25 +0000
commit47f806ce81aac555946144f112b9f8733e2ed871 (patch)
tree346abe5180524c4e459c2f934afaf3c0c9e0157b /src/strconv
parent2730c6af9fb8a7dea9bf610699be0d543aed4da1 (diff)
downloadgo-git-47f806ce81aac555946144f112b9f8733e2ed871.tar.gz
strconv: clarify ParseFloat accepts Go syntax for float literals
The documentation for strconv.ParseFloat mentions that it "accepts decimal and hexadecimal floating-point number syntax", but it doesn't specify what those formats entail. For example, "0x10" is not allowed; you need an explicit exponent, as in "0x10p0". This clarifies that ParseFloat accepts the Go syntax for floating-point literals, and links to that spec section. I've also linked to the relevant spec section for ParseInt's doc comment, which already said "as defined by the Go syntax for integer literals". Change-Id: Ib5d2b408bdd01ea0b9f69381a9dbe858f6d1d424 Reviewed-on: https://go-review.googlesource.com/c/go/+/410335 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/atof.go5
-rw-r--r--src/strconv/atoi.go4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/strconv/atof.go b/src/strconv/atof.go
index 60098efed0..c26c34208c 100644
--- a/src/strconv/atof.go
+++ b/src/strconv/atof.go
@@ -670,7 +670,8 @@ func atof64(s string) (f float64, n int, err error) {
// When bitSize=32, the result still has type float64, but it will be
// convertible to float32 without changing its value.
//
-// ParseFloat accepts decimal and hexadecimal floating-point number syntax.
+// ParseFloat accepts decimal and hexadecimal floating-point numbers
+// as defined by the Go syntax for [floating-point literals].
// If s is well-formed and near a valid floating-point number,
// ParseFloat returns the nearest floating-point number rounded
// using IEEE754 unbiased rounding.
@@ -689,6 +690,8 @@ func atof64(s string) (f float64, n int, err error) {
//
// ParseFloat recognizes the strings "NaN", and the (possibly signed) strings "Inf" and "Infinity"
// as their respective special floating point values. It ignores case when matching.
+//
+// [floating-point literals]: https://go.dev/ref/spec#Floating-point_literals
func ParseFloat(s string, bitSize int) (float64, error) {
f, n, err := parseFloatPrefix(s, bitSize)
if n != len(s) && (err == nil || err.(*NumError).Err != ErrSyntax) {
diff --git a/src/strconv/atoi.go b/src/strconv/atoi.go
index 631b487d97..be08f93356 100644
--- a/src/strconv/atoi.go
+++ b/src/strconv/atoi.go
@@ -167,7 +167,7 @@ func ParseUint(s string, base int, bitSize int) (uint64, error) {
// prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o",
// 16 for "0x", and 10 otherwise. Also, for argument base 0 only,
// underscore characters are permitted as defined by the Go syntax for
-// integer literals.
+// [integer literals].
//
// The bitSize argument specifies the integer type
// that the result must fit into. Bit sizes 0, 8, 16, 32, and 64
@@ -181,6 +181,8 @@ func ParseUint(s string, base int, bitSize int) (uint64, error) {
// signed integer of the given size, err.Err = ErrRange and the
// returned value is the maximum magnitude integer of the
// appropriate bitSize and sign.
+//
+// [integer literals]: https://go.dev/ref/spec#Integer_literals
func ParseInt(s string, base int, bitSize int) (i int64, err error) {
const fnParseInt = "ParseInt"