aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/fmt
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-07-27 22:27:54 -0700
committerIan Lance Taylor <iant@golang.org>2020-08-01 11:21:40 -0700
commitf75af8c1464e948b5e166cf5ab09ebf0d82fc253 (patch)
tree3ba3299859b504bdeb477727471216bd094a0191 /libgo/go/fmt
parent75a23e59031fe673fc3b2e60fd1fe5f4c70ecb85 (diff)
downloadgcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.zip
gcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.tar.gz
gcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.tar.bz2
libgo: update to go1.15rc1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/245157
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r--libgo/go/fmt/fmt_test.go19
-rw-r--r--libgo/go/fmt/format.go13
-rw-r--r--libgo/go/fmt/scan.go8
3 files changed, 30 insertions, 10 deletions
diff --git a/libgo/go/fmt/fmt_test.go b/libgo/go/fmt/fmt_test.go
index b9e3bc6..550c196 100644
--- a/libgo/go/fmt/fmt_test.go
+++ b/libgo/go/fmt/fmt_test.go
@@ -236,10 +236,10 @@ var fmtTests = []struct {
{"%#q", "\U0010ffff", "`􏿿`"},
{"%#+q", "\U0010ffff", "`􏿿`"},
// Runes that are not valid.
- {"%q", string(0x110000), `"�"`},
- {"%+q", string(0x110000), `"\ufffd"`},
- {"%#q", string(0x110000), "`�`"},
- {"%#+q", string(0x110000), "`�`"},
+ {"%q", string(rune(0x110000)), `"�"`},
+ {"%+q", string(rune(0x110000)), `"\ufffd"`},
+ {"%#q", string(rune(0x110000)), "`�`"},
+ {"%#+q", string(rune(0x110000)), "`�`"},
// characters
{"%c", uint('x'), "x"},
@@ -463,6 +463,15 @@ var fmtTests = []struct {
{"%#.4x", 1.0, "0x1.0000p+00"},
{"%#.4g", 1.0, "1.000"},
{"%#.4g", 100000.0, "1.000e+05"},
+ {"%#.4g", 1.234, "1.234"},
+ {"%#.4g", 0.1234, "0.1234"},
+ {"%#.4g", 1.23, "1.230"},
+ {"%#.4g", 0.123, "0.1230"},
+ {"%#.4g", 1.2, "1.200"},
+ {"%#.4g", 0.12, "0.1200"},
+ {"%#.4g", 10.2, "10.20"},
+ {"%#.4g", 0.0, "0.000"},
+ {"%#.4g", 0.012, "0.01200"},
{"%#.0f", 123.0, "123."},
{"%#.0e", 123.0, "1.e+02"},
{"%#.0x", 123.0, "0x1.p+07"},
@@ -1459,7 +1468,7 @@ func (flagPrinter) Format(f State, c rune) {
s := "%"
for i := 0; i < 128; i++ {
if f.Flag(i) {
- s += string(i)
+ s += string(rune(i))
}
}
if w, ok := f.Width(); ok {
diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go
index 74e600c..4d12f82 100644
--- a/libgo/go/fmt/format.go
+++ b/libgo/go/fmt/format.go
@@ -536,6 +536,7 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
tail := tailBuf[:0]
hasDecimalPoint := false
+ sawNonzeroDigit := false
// Starting from i = 1 to skip sign at num[0].
for i := 1; i < len(num); i++ {
switch num[i] {
@@ -552,10 +553,20 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) {
}
fallthrough
default:
- digits--
+ if num[i] != '0' {
+ sawNonzeroDigit = true
+ }
+ // Count significant digits after the first non-zero digit.
+ if sawNonzeroDigit {
+ digits--
+ }
}
}
if !hasDecimalPoint {
+ // Leading digit 0 should contribute once to digits.
+ if len(num) == 2 && num[1] == '0' {
+ digits--
+ }
num = append(num, '.')
}
for digits > 0 {
diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go
index 8cab018..3815770 100644
--- a/libgo/go/fmt/scan.go
+++ b/libgo/go/fmt/scan.go
@@ -600,13 +600,13 @@ func (s *ss) scanNumber(digits string, haveDigits bool) string {
// scanRune returns the next rune value in the input.
func (s *ss) scanRune(bitSize int) int64 {
s.notEOF()
- r := int64(s.getRune())
+ r := s.getRune()
n := uint(bitSize)
- x := (r << (64 - n)) >> (64 - n)
- if x != r {
+ x := (int64(r) << (64 - n)) >> (64 - n)
+ if x != int64(r) {
s.errorString("overflow on character value " + string(r))
}
- return r
+ return int64(r)
}
// scanBasePrefix reports whether the integer begins with a base prefix