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

Use total ordering for floats? #123

Open
brson opened this issue Feb 10, 2022 · 1 comment
Open

Use total ordering for floats? #123

brson opened this issue Feb 10, 2022 · 1 comment
Labels
question Further information is requested

Comments

@brson
Copy link
Contributor

brson commented Feb 10, 2022

In #115 @nikomatsakis suggested dada might use a total ordering for floats.

The standard behavior of nans is a big source of frustration without much benefit. It would be convenient to get rid of it.

I myself don't understand the implications of defining floats to have a total ordering.

@nikomatsakis nikomatsakis added the question Further information is requested label Feb 10, 2022
@nikomatsakis
Copy link
Member

nikomatsakis commented Feb 10, 2022

Implications I can think of:

  • Huge source of bugs and confusion gone, and things like hashmaps or btrees composed of floats work just fine.

But:

  • Inconsistent with virtually every other language
  • Have to use somewhat slower hardware operations or compile things in somewhat slower way
  • May affect ability to SIMD-parallelize operations like [float] < [float]? Not sure

The last two points seem important.

There is one final unknown:

  • Does anybody want the IEEE behavior? I imagine that it was defined this way for a reason, that if you're doing dense numerical computation, it is useful to have NaN <= NaN (etc) be false, but I've only heard one person "stick up" for it to me in conversation, and quite frankly their argument was unconvincing. It seems to me that you very well might want NaN <= NaN to be false, but you equally well might want the opposite, it will very much depend on what you are doing with the result of that comparison. And if you have to think about NaN anyway than I suspect you could as well account for total ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants