aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/strconv/ftoa.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/strconv/ftoa.go')
-rw-r--r--libgo/go/strconv/ftoa.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/libgo/go/strconv/ftoa.go b/libgo/go/strconv/ftoa.go
index 8ce6ef3..eca04b8 100644
--- a/libgo/go/strconv/ftoa.go
+++ b/libgo/go/strconv/ftoa.go
@@ -113,15 +113,11 @@ func genericFtoa(dst []byte, val float64, fmt byte, prec, bitSize int) []byte {
// Negative precision means "only as much as needed to be exact."
shortest := prec < 0
if shortest {
- // Try Grisu3 algorithm.
- f := new(extFloat)
- lower, upper := f.AssignComputeBounds(mant, exp, neg, flt)
+ // Use Ryu algorithm.
var buf [32]byte
digs.d = buf[:]
- ok = f.ShortestDecimal(&digs, &lower, &upper)
- if !ok {
- return bigFtoa(dst, prec, fmt, neg, mant, exp, flt)
- }
+ ryuFtoaShortest(&digs, mant, exp-int(flt.mantbits), flt)
+ ok = true
// Precision for shortest representation mode.
switch fmt {
case 'e', 'E':
@@ -143,12 +139,15 @@ func genericFtoa(dst []byte, val float64, fmt byte, prec, bitSize int) []byte {
}
digits = prec
}
- if digits <= 15 {
- // try fast algorithm when the number of digits is reasonable.
- var buf [24]byte
+ var buf [24]byte
+ if bitSize == 32 && digits <= 9 {
+ digs.d = buf[:]
+ ryuFtoaFixed32(&digs, uint32(mant), exp-int(flt.mantbits), digits)
+ ok = true
+ } else if digits <= 18 {
digs.d = buf[:]
- f := extFloat{mant, exp - int(flt.mantbits), neg}
- ok = f.FixedDecimal(&digs, digits)
+ ryuFtoaFixed64(&digs, mant, exp-int(flt.mantbits), digits)
+ ok = true
}
}
if !ok {