diff options
Diffstat (limited to 'src/pkg/strconv/ftoa.go')
-rw-r--r-- | src/pkg/strconv/ftoa.go | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/pkg/strconv/ftoa.go b/src/pkg/strconv/ftoa.go index d31f44142..a285b6402 100644 --- a/src/pkg/strconv/ftoa.go +++ b/src/pkg/strconv/ftoa.go @@ -73,12 +73,12 @@ func Ftoa(f float, fmt byte, prec int) string { } func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string { - neg := bits >> flt.expbits >> flt.mantbits != 0; - exp := int(bits >> flt.mantbits)&(1 << flt.expbits - 1); - mant := bits&(uint64(1) << flt.mantbits - 1); + neg := bits>>flt.expbits>>flt.mantbits != 0; + exp := int(bits>>flt.mantbits) & (1<<flt.expbits - 1); + mant := bits & (uint64(1)<<flt.mantbits - 1); switch exp { - case 1 << flt.expbits - 1: + case 1<<flt.expbits - 1: // Inf, NaN if mant != 0 { return "NaN" @@ -107,7 +107,7 @@ 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).Shift(exp-int(flt.mantbits)); + d := newDecimal(mant).Shift(exp - int(flt.mantbits)); // Round appropriately. // Negative precision means "only as much as needed to be exact." @@ -119,14 +119,14 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string { case 'e', 'E': prec = d.nd - 1 case 'f': - prec = max(d.nd - d.dp, 0) + prec = max(d.nd-d.dp, 0) case 'g', 'G': prec = d.nd } } else { switch fmt { case 'e', 'E': - d.Round(prec+1) + d.Round(prec + 1) case 'f': d.Round(d.dp + prec) case 'g', 'G': @@ -158,10 +158,10 @@ func genericFtoa(bits uint64, fmt byte, prec int, flt *floatInfo) string { if exp < -4 || exp >= eprec { return fmtE(neg, d, prec-1, fmt+'e'-'g') } - return fmtF(neg, d, max(prec - d.dp, 0)); + return fmtF(neg, d, max(prec-d.dp, 0)); } - return "%"+string(fmt); + return "%" + string(fmt); } // Round d (= mant * 2^exp) to the shortest number of digits @@ -186,7 +186,7 @@ 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).Shift(exp-int(flt.mantbits)-1); + upper := newDecimal(mant*2 + 1).Shift(exp - int(flt.mantbits) - 1); // d = mant << (exp - mantbits) // Next lowest floating point number is mant-1 << exp-mantbits, @@ -197,14 +197,14 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) { minexp := flt.bias + 1; // minimum possible exponent var mantlo uint64; var explo int; - if mant > 1 << flt.mantbits || exp == minexp { - mantlo = mant-1; + if mant > 1<<flt.mantbits || exp == minexp { + mantlo = mant - 1; explo = exp; } else { mantlo = mant*2 - 1; - explo = exp-1; + explo = exp - 1; } - lower := newDecimal(mantlo*2 + 1).Shift(explo-int(flt.mantbits)-1); + lower := newDecimal(mantlo*2 + 1).Shift(explo - int(flt.mantbits) - 1); // The upper and lower bounds are possible outputs only if // the original mantissa is even, so that IEEE round-to-even @@ -239,13 +239,13 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) { // If it's okay to do only one, do it. switch { case okdown && okup: - d.Round(i+1); + d.Round(i + 1); return; case okdown: - d.RoundDown(i+1); + d.RoundDown(i + 1); return; case okup: - d.RoundUp(i+1); + d.RoundUp(i + 1); return; } } @@ -253,8 +253,8 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) { // %e: -d.ddddde±dd func fmtE(neg bool, d *decimal, prec int, fmt byte) string { - buf := make([]byte, 3 + max(prec, 0) + 30); // "-0." + prec digits + exp - w := 0; // write index + buf := make([]byte, 3+max(prec, 0)+30); // "-0." + prec digits + exp + w := 0; // write index // sign if neg { @@ -323,7 +323,7 @@ func fmtE(neg bool, d *decimal, prec int, fmt byte) string { // %f: -ddddddd.ddddd func fmtF(neg bool, d *decimal, prec int) string { - buf := make([]byte, 1 + max(d.dp, 1) + 1 + max(prec, 0)); + buf := make([]byte, 1+max(d.dp, 1)+1+max(prec, 0)); w := 0; // sign @@ -353,10 +353,10 @@ func fmtF(neg bool, d *decimal, prec int) string { buf[w] = '.'; w++; for i := 0; i < prec; i++ { - if d.dp + i < 0 || d.dp + i >= d.nd { + if d.dp+i < 0 || d.dp+i >= d.nd { buf[w] = '0' } else { - buf[w] = d.d[d.dp + i] + buf[w] = d.d[d.dp+i] } w++; } |