Skip to content

Commit

Permalink
prevent unwanted promotions of integers to float (Issue 427)
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptory committed Nov 10, 2024
1 parent 8f36c1b commit 6584fb2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ func (e *Encoder) encodeFloat(v float64, bitSize int) ast.Node {
// append x.0 suffix to keep float value context
value = fmt.Sprintf("%s.0", value)
}

// prevent unwanted promotions of integers to float (Issue 427)
intVal := int64(v)
if float64(intVal) == v {
value := fmt.Sprint(intVal)
return ast.Integer(token.New(value, value, e.pos(e.column)))
}

return ast.Float(token.New(value, value, e.pos(e.column)))
}

Expand Down

0 comments on commit 6584fb2

Please sign in to comment.