Match float literals to float32 comparisons#983
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
Float literals are normally compiled as float64 values, which makes comparisons against float32 operands use different rounded values. Patch literals in those comparisons to float32 after type checking so optimized and unoptimized programs follow Go's literal conversion behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
deepakganesh78
force-pushed
the
fix/issue609-float32-literals
branch
from
July 26, 2026 11:38
29fc629 to
75aa119
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #609
Root cause
Expr compiles floating-point literals as
float64. Comparing one directly with afloat32operand therefore compares the roundedfloat32value with the originalfloat64literal, unlike Go's conversion of the untyped literal tofloat32.Fix
After type checking, patch float literals used directly in comparisons with
float32operands into typedfloat32constants. This handles either operand order and signed literals without changing mixedfloat32/float64arithmetic.Tests
go test .\checker . -run 'Test(Float32LiteralComparisons|Check)' -count=1go test ./...go test -tags=expr_debug -run=TestDebugger -v ./vmgo vet ./...The regression test covers optimized and unoptimized compilation, both operand orders, signed literals, relational and inequality comparisons, and verifies
float64behavior remains unchanged.go test -race .was not available on this Windows host because the installed Go toolchain has CGO disabled.