MCPcopy
hub / github.com/uber-go/zap / appendComplex

Method appendComplex

zapcore/json_encoder.go:247–263  ·  view source on GitHub ↗

appendComplex appends the encoded form of the provided complex128 value. precision specifies the encoding precision for the real and imaginary components of the complex number.

(val complex128, precision int)

Source from the content-addressed store, hash-verified

245// precision specifies the encoding precision for the real and imaginary
246// components of the complex number.
247func (enc *jsonEncoder) appendComplex(val complex128, precision int) {
248 enc.addElementSeparator()
249 // Cast to a platform-independent, fixed-size type.
250 r, i := float64(real(val)), float64(imag(val))
251 enc.buf.AppendByte('"')
252 // Because we're always in a quoted string, we can use strconv without
253 // special-casing NaN and +/-Inf.
254 enc.buf.AppendFloat(r, precision)
255 // If imaginary part is less than 0, minus (-) sign is added by default
256 // by AppendFloat.
257 if i >= 0 {
258 enc.buf.AppendByte('+')
259 }
260 enc.buf.AppendFloat(i, precision)
261 enc.buf.AppendByte('i')
262 enc.buf.AppendByte('"')
263}
264
265func (enc *jsonEncoder) AppendDuration(val time.Duration) {
266 cur := enc.buf.Len()

Callers 2

AppendComplex64Method · 0.95
AppendComplex128Method · 0.95

Calls 3

addElementSeparatorMethod · 0.95
AppendByteMethod · 0.80
AppendFloatMethod · 0.80

Tested by

no test coverage detected