From 6584fb2d43aebbdd19600fab67cece8ea7a36833 Mon Sep 17 00:00:00 2001 From: Thomas Dell Date: Sun, 10 Nov 2024 22:16:13 +0000 Subject: [PATCH] prevent unwanted promotions of integers to float (Issue 427) --- encode.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/encode.go b/encode.go index 97c1fa5b..35690eac 100644 --- a/encode.go +++ b/encode.go @@ -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))) }