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

Function formatDigits

fflib/v1/ftoa.go:185–223  ·  view source on GitHub ↗
(dst EncodingBuffer, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte)

Source from the content-addressed store, hash-verified

183}
184
185func formatDigits(dst EncodingBuffer, shortest bool, neg bool, digs decimalSlice, prec int, fmt byte) {
186 switch fmt {
187 case 'e', 'E':
188 fmtE(dst, neg, digs, prec, fmt)
189 return
190 case 'f':
191 fmtF(dst, neg, digs, prec)
192 return
193 case 'g', 'G':
194 // trailing fractional zeros in 'e' form will be trimmed.
195 eprec := prec
196 if eprec > digs.nd && digs.nd >= digs.dp {
197 eprec = digs.nd
198 }
199 // %e is used if the exponent from the conversion
200 // is less than -4 or greater than or equal to the precision.
201 // if precision was the shortest possible, use precision 6 for this decision.
202 if shortest {
203 eprec = 6
204 }
205 exp := digs.dp - 1
206 if exp < -4 || exp >= eprec {
207 if prec > digs.nd {
208 prec = digs.nd
209 }
210 fmtE(dst, neg, digs, prec-1, fmt+'e'-'g')
211 return
212 }
213 if prec > digs.dp {
214 prec = digs.nd
215 }
216 fmtF(dst, neg, digs, max(prec-digs.dp, 0))
217 return
218 }
219
220 // unknown format
221 dst.Write([]byte{'%', fmt})
222 return
223}
224
225// Round d (= mant * 2^exp) to the shortest number of digits
226// that will let the original floating point value be precisely

Callers 2

AppendFloatFunction · 0.70
bigFtoaFunction · 0.70

Calls 4

fmtEFunction · 0.70
fmtFFunction · 0.70
maxFunction · 0.70
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…