| 539 | } |
| 540 | |
| 541 | func (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 | |
| 563 | func (e *Encoder) isNeedQuoted(v string) bool { |
| 564 | if e.isJSONStyle { |