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

Function fmtE

fflib/v1/ftoa.go:333–390  ·  view source on GitHub ↗

%e: -d.ddddde±dd

(dst EncodingBuffer, neg bool, d decimalSlice, prec int, fmt byte)

Source from the content-addressed store, hash-verified

331
332// %e: -d.ddddde±dd
333func fmtE(dst EncodingBuffer, neg bool, d decimalSlice, prec int, fmt byte) {
334 // sign
335 if neg {
336 dst.WriteByte('-')
337 }
338
339 // first digit
340 ch := byte('0')
341 if d.nd != 0 {
342 ch = d.d[0]
343 }
344 dst.WriteByte(ch)
345
346 // .moredigits
347 if prec > 0 {
348 dst.WriteByte('.')
349 i := 1
350 m := min(d.nd, prec+1)
351 if i < m {
352 dst.Write(d.d[i:m])
353 i = m
354 }
355 for i <= prec {
356 dst.WriteByte('0')
357 i++
358 }
359 }
360
361 // e±
362 dst.WriteByte(fmt)
363 exp := d.dp - 1
364 if d.nd == 0 { // special case: 0 has exponent 0
365 exp = 0
366 }
367 if exp < 0 {
368 ch = '-'
369 exp = -exp
370 } else {
371 ch = '+'
372 }
373 dst.WriteByte(ch)
374
375 // dd or ddd
376 switch {
377 case exp < 10:
378 dst.WriteByte('0')
379 dst.WriteByte(byte(exp) + '0')
380 case exp < 100:
381 dst.WriteByte(byte(exp/10) + '0')
382 dst.WriteByte(byte(exp%10) + '0')
383 default:
384 dst.WriteByte(byte(exp/100) + '0')
385 dst.WriteByte(byte(exp/10)%10 + '0')
386 dst.WriteByte(byte(exp%10) + '0')
387 }
388
389 return
390}

Callers 1

formatDigitsFunction · 0.70

Calls 3

minFunction · 0.85
WriteByteMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…