summaryrefslogtreecommitdiff
path: root/libgo/go/strconv
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-12 23:40:51 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-12 23:40:51 +0000
commitab61e9c4da707f3bc7b177c0c8f92daccdb142dc (patch)
tree0c68629fac9d7c6f103b401c9063ef00ed259f06 /libgo/go/strconv
parent6e456f4cf4deee3e2ccd9849286f59b90644c48b (diff)
downloadgcc-ab61e9c4da707f3bc7b177c0c8f92daccdb142dc.tar.gz
libgo: Update to weekly.2011-11-18.
From-SVN: r182266
Diffstat (limited to 'libgo/go/strconv')
-rw-r--r--libgo/go/strconv/decimal.go27
-rw-r--r--libgo/go/strconv/decimal_test.go12
-rw-r--r--libgo/go/strconv/ftoa.go9
-rw-r--r--libgo/go/strconv/ftoa_test.go24
-rw-r--r--libgo/go/strconv/internal_test.go6
5 files changed, 54 insertions, 24 deletions
diff --git a/libgo/go/strconv/decimal.go b/libgo/go/strconv/decimal.go
index f572ea4a22d..541553097bb 100644
--- a/libgo/go/strconv/decimal.go
+++ b/libgo/go/strconv/decimal.go
@@ -102,12 +102,6 @@ func (a *decimal) Assign(v uint64) {
trim(a)
}
-func newDecimal(i uint64) *decimal {
- a := new(decimal)
- a.Assign(i)
- return a
-}
-
// Maximum shift that we can do in one pass without overflow.
// Signed int has 31 bits, and we have to be able to accommodate 9<<k.
const maxShift = 27
@@ -303,32 +297,32 @@ func shouldRoundUp(a *decimal, nd int) bool {
// If nd is zero, it means we're rounding
// just to the left of the digits, as in
// 0.09 -> 0.1.
-func (a *decimal) Round(nd int) *decimal {
+func (a *decimal) Round(nd int) {
if nd < 0 || nd >= a.nd {
- return a
+ return
}
if shouldRoundUp(a, nd) {
- return a.RoundUp(nd)
+ a.RoundUp(nd)
+ } else {
+ a.RoundDown(nd)
}
- return a.RoundDown(nd)
}
// Round a down to nd digits (or fewer).
// Returns receiver for convenience.
-func (a *decimal) RoundDown(nd int) *decimal {
+func (a *decimal) RoundDown(nd int) {
if nd < 0 || nd >= a.nd {
- return a
+ return
}
a.nd = nd
trim(a)
- return a
}
// Round a up to nd digits (or fewer).
// Returns receiver for convenience.
-func (a *decimal) RoundUp(nd int) *decimal {
+func (a *decimal) RoundUp(nd int) {
if nd < 0 || nd >= a.nd {
- return a
+ return
}
// round up
@@ -337,7 +331,7 @@ func (a *decimal) RoundUp(nd int) *decimal {
if c < '9' { // can stop after this digit
a.d[i]++
a.nd = i + 1
- return a
+ return
}
}
@@ -346,7 +340,6 @@ func (a *decimal) RoundUp(nd int) *decimal {
a.d[0] = '1'
a.nd = 1
a.dp++
- return a
}
// Extract integer part, rounded appropriately.
diff --git a/libgo/go/strconv/decimal_test.go b/libgo/go/strconv/decimal_test.go
index deb2e02f610..13a127f5b2c 100644
--- a/libgo/go/strconv/decimal_test.go
+++ b/libgo/go/strconv/decimal_test.go
@@ -70,17 +70,23 @@ var roundtests = []roundTest{
func TestDecimalRound(t *testing.T) {
for i := 0; i < len(roundtests); i++ {
test := &roundtests[i]
- s := NewDecimal(test.i).RoundDown(test.nd).String()
+ d := NewDecimal(test.i)
+ d.RoundDown(test.nd)
+ s := d.String()
if s != test.down {
t.Errorf("Decimal %v RoundDown %d = %v, want %v",
test.i, test.nd, s, test.down)
}
- s = NewDecimal(test.i).Round(test.nd).String()
+ d = NewDecimal(test.i)
+ d.Round(test.nd)
+ s = d.String()
if s != test.round {
t.Errorf("Decimal %v Round %d = %v, want %v",
test.i, test.nd, s, test.down)
}
- s = NewDecimal(test.i).RoundUp(test.nd).String()
+ d = NewDecimal(test.i)
+ d.RoundUp(test.nd)
+ s = d.String()
if s != test.up {
t.Errorf("Decimal %v RoundUp %d = %v, want %v",
test.i, test.nd, s, test.up)
diff --git a/libgo/go/strconv/ftoa.go b/libgo/go/strconv/ftoa.go
index 07fe806b97d..8342b6abe79 100644
--- a/libgo/go/strconv/ftoa.go
+++ b/libgo/go/strconv/ftoa.go
@@ -98,7 +98,8 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string {
// The shift is exp - flt.mantbits because mant is a 1-bit integer
// followed by a flt.mantbits fraction, and we are treating it as
// a 1+flt.mantbits-bit integer.
- d := newDecimal(mant)
+ d := new(decimal)
+ d.Assign(mant)
d.Shift(exp - int(flt.mantbits))
// Round appropriately.
@@ -184,7 +185,8 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
// d = mant << (exp - mantbits)
// Next highest floating point number is mant+1 << exp-mantbits.
// Our upper bound is halfway inbetween, mant*2+1 << exp-mantbits-1.
- upper := newDecimal(mant*2 + 1)
+ upper := new(decimal)
+ upper.Assign(mant*2 + 1)
upper.Shift(exp - int(flt.mantbits) - 1)
// d = mant << (exp - mantbits)
@@ -203,7 +205,8 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
mantlo = mant*2 - 1
explo = exp - 1
}
- lower := newDecimal(mantlo*2 + 1)
+ lower := new(decimal)
+ lower.Assign(mantlo*2 + 1)
lower.Shift(explo - int(flt.mantbits) - 1)
// The upper and lower bounds are possible outputs only if
diff --git a/libgo/go/strconv/ftoa_test.go b/libgo/go/strconv/ftoa_test.go
index 6d361a138ef..8bac5da4526 100644
--- a/libgo/go/strconv/ftoa_test.go
+++ b/libgo/go/strconv/ftoa_test.go
@@ -148,3 +148,27 @@ func TestFtoa(t *testing.T) {
}
}
}
+
+func BenchmarkFtoa64Decimal(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Ftoa64(33909, 'g', -1)
+ }
+}
+
+func BenchmarkFtoa64Float(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Ftoa64(339.7784, 'g', -1)
+ }
+}
+
+func BenchmarkFtoa64FloatExp(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Ftoa64(-5.09e75, 'g', -1)
+ }
+}
+
+func BenchmarkFtoa64Big(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Ftoa64(123456789123456789123456789, 'g', -1)
+ }
+}
diff --git a/libgo/go/strconv/internal_test.go b/libgo/go/strconv/internal_test.go
index 9a7f4f0867c..d0fa80edfb6 100644
--- a/libgo/go/strconv/internal_test.go
+++ b/libgo/go/strconv/internal_test.go
@@ -6,7 +6,11 @@
package strconv
-func NewDecimal(i uint64) *decimal { return newDecimal(i) }
+func NewDecimal(i uint64) *decimal {
+ d := new(decimal)
+ d.Assign(i)
+ return d
+}
func SetOptimize(b bool) bool {
old := optimize