-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #370 - implement proper ER-mode comparison for floating point types #373
Conversation
I merged you changes into #372 and our sorting tests become green ;-) |
👍 This is fantastic! I had no clue how to get around NaNs when doing the SortBy, turns out I was only about 2 levels of abstractions away from enlightenment. |
elif (# "ceq" x y : bool #) then (0) | ||
elif (# "ceq" x x : bool #) then (1) | ||
elif (# "ceq" y y : bool #) then (-1) | ||
else (0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reordering the nan comparisons we can eliminate a branch
when 'T : float = if (# "clt" x y : bool #) then (-1)
elif (# "cgt" x y : bool #) then (1)
elif (# "ceq" x y : bool #) then (0)
elif (# "ceq" y y : bool #) then (-1)
else (# "ceq" x x : bool #)
It's similar to what was done here previously, but doesn't avoid any extra IL calls and is arguably less clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I think you mean (# "ceq" x x : int #)
on the last line (return the ceq
result as int value 1 or 0, not bool value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I meant 😊
Nice work - great fix, great testing. |
Looks great |
Fixes #370. Root cause was that
GenericComparisonFast
did not have an accurate implementation of ER-mode floating point comparison. Testing showed that nonstructuralcompare
had the same issue.The added
compre
tests here should cover the code well enough, but I'm also planning to add some actual floating-point sorting tests to the core unittests.