Repository navigation
Compare an int and a float exactly instead of rounding the int to float - #257
Open
Dilshad-Tanvi wants to merge 1 commit into
Open
Dilshad-Tanvi wants to merge 1 commit into
Dilshad-Tanvi wants to merge 1 commit into
Conversation
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.) |
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.
NumRef'seqandcmp, which back==,<,sorted,inand dict/set key lookup for every int/float mix, round a big int tof64before comparing. So(1 << 53) + 1 == float(1 << 53)isTrue,(1 << 53) + 1 > float(1 << 53)isFalse, and(1 << 2000) == float("inf")isTruebecause 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 throughbig.Rat. Thefloat.starconformance lines that check exactly this (p53, the1.23e45neighbours,maxint64) were being filtered out intests/go.rs.Small ints still compare as
f64, which is exact fori32. A big int is compared againstfloor(f)as aBigInt, with any fractional part breaking the tie, and non-finite floats sort above or below every int.eqnow goes throughcmp, 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.