MCPcopy Create free account
hub / github.com/goccy/go-yaml / encodeFloat

Method encodeFloat

encode.go:541–561  ·  view source on GitHub ↗
(v float64, bitSize int)

Source from the content-addressed store, hash-verified

539}
540
541func (e *Encoder) encodeFloat(v float64, bitSize int) ast.Node {
542 if v == math.Inf(0) {
543 value := ".inf"
544 return ast.Infinity(token.New(value, value, e.pos(e.column)))
545 } else if v == math.Inf(-1) {
546 value := "-.inf"
547 return ast.Infinity(token.New(value, value, e.pos(e.column)))
548 } else if math.IsNaN(v) {
549 value := ".nan"
550 return ast.Nan(token.New(value, value, e.pos(e.column)))
551 }
552 value := strconv.FormatFloat(v, 'g', -1, bitSize)
553 if !strings.Contains(value, ".") && !strings.Contains(value, "e") {
554 if e.autoInt {
555 return ast.Integer(token.New(value, value, e.pos(e.column)))
556 }
557 // append x.0 suffix to keep float value context
558 value = fmt.Sprintf("%s.0", value)
559 }
560 return ast.Float(token.New(value, value, e.pos(e.column)))
561}
562
563func (e *Encoder) isNeedQuoted(v string) bool {
564 if e.isJSONStyle {

Callers 1

encodeValueMethod · 0.95

Calls 6

posMethod · 0.95
InfinityFunction · 0.92
NewFunction · 0.92
NanFunction · 0.92
IntegerFunction · 0.92
FloatFunction · 0.92

Tested by

no test coverage detected