From: Ben Hoyt Date: Sat, 4 Jun 2022 06:31:40 +0000 (+1200) Subject: strconv: clarify ParseFloat accepts Go syntax for float literals X-Git-Tag: go1.19beta1~65 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=47f806ce81;p=gostls13.git 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 TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov Auto-Submit: Ian Lance Taylor --- 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"