]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: clarify ParseFloat accepts Go syntax for float literals
authorBen Hoyt <benhoyt@gmail.com>
Sat, 4 Jun 2022 06:31:40 +0000 (18:31 +1200)
committerGopher Robot <gobot@golang.org>
Sat, 4 Jun 2022 21:18:25 +0000 (21:18 +0000)
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>

src/strconv/atof.go
src/strconv/atoi.go

index 60098efed0acff62bf4bac06e5476bb297ab1ab0..c26c34208c71677bc9bf395fa8805d521df860c1 100644 (file)
@@ -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) {
index 631b487d9762bb71368b619e66feb454e5379bc2..be08f9335600a3ac143e4a8d84faf8907edc75af 100644 (file)
@@ -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"