bigFtoa uses multiprecision computations to format a float.
(dst EncodingBuffer, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo)
| 146 | |
| 147 | // bigFtoa uses multiprecision computations to format a float. |
| 148 | func bigFtoa(dst EncodingBuffer, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo) { |
| 149 | d := new(decimal) |
| 150 | d.Assign(mant) |
| 151 | d.Shift(exp - int(flt.mantbits)) |
| 152 | var digs decimalSlice |
| 153 | shortest := prec < 0 |
| 154 | if shortest { |
| 155 | roundShortest(d, mant, exp, flt) |
| 156 | digs = decimalSlice{d: d.d[:], nd: d.nd, dp: d.dp} |
| 157 | // Precision for shortest representation mode. |
| 158 | switch fmt { |
| 159 | case 'e', 'E': |
| 160 | prec = digs.nd - 1 |
| 161 | case 'f': |
| 162 | prec = max(digs.nd-digs.dp, 0) |
| 163 | case 'g', 'G': |
| 164 | prec = digs.nd |
| 165 | } |
| 166 | } else { |
| 167 | // Round appropriately. |
| 168 | switch fmt { |
| 169 | case 'e', 'E': |
| 170 | d.Round(prec + 1) |
| 171 | case 'f': |
| 172 | d.Round(d.dp + prec) |
| 173 | case 'g', 'G': |
| 174 | if prec == 0 { |
| 175 | prec = 1 |
| 176 | } |
| 177 | d.Round(prec) |
| 178 | } |
| 179 | digs = decimalSlice{d: d.d[:], nd: d.nd, dp: d.dp} |
| 180 | } |
| 181 | formatDigits(dst, shortest, neg, digs, prec, fmt) |
| 182 | return |
| 183 | } |
| 184 | |
| 185 | func formatDigits(dst EncodingBuffer, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte) { |
| 186 | switch fmt { |
no test coverage detected
searching dependent graphs…