Skip to content

Compare an int and a float exactly instead of rounding the int to float - #257

Open
Dilshad-Tanvi wants to merge 1 commit into
facebook:mainfrom
Dilshad-Tanvi:int-float-exact-compare
Open

Dilshad-Tanvi wants to merge 1 commit into
facebook:mainfrom
Dilshad-Tanvi:int-float-exact-compare

Conversation

@Dilshad-Tanvi

Copy link
Copy Markdown
Contributor

NumRef's eq and cmp, which back ==, <, sorted, in and dict/set key lookup for every int/float mix, round a big int to f64 before comparing. So (1 << 53) + 1 == float(1 << 53) is True, (1 << 53) + 1 > float(1 << 53) is False, and (1 << 2000) == float("inf") is True because the int rounds to infinity. The spec says mixed int/float comparison is mathematically exact even when neither operand fits the other's type, and starlark-go compares through big.Rat. The float.star conformance lines that check exactly this (p53, the 1.23e45 neighbours, maxint64) were being filtered out in tests/go.rs.

Small ints still compare as f64, which is exact for i32. A big int is compared against floor(f) as a BigInt, with any fractional part breaking the tie, and non-finite floats sort above or below every int. eq now goes through cmp, so equality only gets stricter and equal values still hash the same. The filtered conformance lines now run and pass. #254 left comparisons alone on purpose, and this covers them.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 24, 2026
@meta-codesync

meta-codesync Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D127353263. (Because this pull request was imported automatically, there will not be any future comments.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant