Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

latkin
Copy link
Contributor

@latkin latkin commented Apr 21, 2015

Fixes #370. Root cause was that GenericComparisonFast did not have an accurate implementation of ER-mode floating point comparison. Testing showed that nonstructural compare 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.

@forki
Copy link
Contributor

forki commented Apr 21, 2015

I merged you changes into #372 and our sorting tests become green ;-)

@PatrickMcDonald
Copy link
Contributor

👍 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)
Copy link
Contributor

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

Copy link
Contributor Author

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)

Copy link
Contributor

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 😊

@dsyme
Copy link
Contributor

dsyme commented Apr 22, 2015

Nice work - great fix, great testing.

@KevinRansom
Copy link
Member

Looks great

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.

6 participants