Skip to content

Commit 75736cc

Browse files
ianlancetaylorgopherbot
authored andcommitted
fmt, strconv: document that exponent is always two digits
Except for %b where it is only one. Fixes #70862 Change-Id: Ic423a799b73bfa534f4083f6544bb9cd639fef06 Reviewed-on: https://go-review.googlesource.com/c/go/+/636915 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 1218566 commit 75736cc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/fmt/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Floating-point and complex constituents:
5050
%x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20
5151
%X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20
5252
53+
The exponent is always a decimal integer.
54+
For formats other than %b the exponent is at least two digits.
55+
5356
String and slice of bytes (treated equivalently with these verbs):
5457
5558
%s the uninterpreted bytes of the string or slice

src/strconv/ftoa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var float64info = floatInfo{52, 11, -1023}
4444
// zeros are removed).
4545
// The special precision -1 uses the smallest number of digits
4646
// necessary such that ParseFloat will return f exactly.
47+
// The exponent is written as a decimal integer;
48+
// for all formats other than 'b', it will be at least two digits.
4749
func FormatFloat(f float64, fmt byte, prec, bitSize int) string {
4850
return string(genericFtoa(make([]byte, 0, max(prec+4, 24)), f, fmt, prec, bitSize))
4951
}

0 commit comments

Comments
 (0)