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)
| 245 | // precision specifies the encoding precision for the real and imaginary |
| 246 | // components of the complex number. |
| 247 | func (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 | |
| 265 | func (enc *jsonEncoder) AppendDuration(val time.Duration) { |
| 266 | cur := enc.buf.Len() |
no test coverage detected