Skip to content

Match float literals to float32 comparisons#983

Open
deepakganesh78 wants to merge 1 commit into
expr-lang:masterfrom
deepakganesh78:fix/issue609-float32-literals
Open

Match float literals to float32 comparisons#983
deepakganesh78 wants to merge 1 commit into
expr-lang:masterfrom
deepakganesh78:fix/issue609-float32-literals

Conversation

@deepakganesh78

Copy link
Copy Markdown

Fixes #609

Root cause

Expr compiles floating-point literals as float64. Comparing one directly with a float32 operand therefore compares the rounded float32 value with the original float64 literal, unlike Go's conversion of the untyped literal to float32.

Fix

After type checking, patch float literals used directly in comparisons with float32 operands into typed float32 constants. This handles either operand order and signed literals without changing mixed float32/float64 arithmetic.

Tests

  • go test .\checker . -run 'Test(Float32LiteralComparisons|Check)' -count=1
  • go test ./...
  • go test -tags=expr_debug -run=TestDebugger -v ./vm
  • go vet ./...

The regression test covers optimized and unoptimized compilation, both operand orders, signed literals, relational and inequality comparisons, and verifies float64 behavior remains unchanged.

go test -race . was not available on this Windows host because the installed Go toolchain has CGO disabled.

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
deepakganesh78 force-pushed the fix/issue609-float32-literals branch from 29fc629 to 75aa119 Compare July 26, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cast IntegerNode to float32 in operations like f32 == 1.5

1 participant