MCPcopy
hub / github.com/pquerna/ffjson / bigFtoa

Function bigFtoa

fflib/v1/ftoa.go:148–183  ·  view source on GitHub ↗

bigFtoa uses multiprecision computations to format a float.

(dst EncodingBuffer, prec int, fmt byte, neg bool, mant uint64, exp int, flt *floatInfo)

Source from the content-addressed store, hash-verified

146
147// bigFtoa uses multiprecision computations to format a float.
148func 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
185func formatDigits(dst EncodingBuffer, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte) {
186 switch fmt {

Callers 1

AppendFloatFunction · 0.70

Calls 6

roundShortestFunction · 0.70
maxFunction · 0.70
formatDigitsFunction · 0.70
AssignMethod · 0.45
ShiftMethod · 0.45
RoundMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…