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

unstable_sort_by panics when given NaN #9

Closed
Roughsketch opened this issue Apr 22, 2019 · 1 comment
Closed

unstable_sort_by panics when given NaN #9

Roughsketch opened this issue Apr 22, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@Roughsketch
Copy link

There is a panic on the following line when one of the values is NaN:

dists.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap());

You can get around this by implementing a default ordering with something like

dists.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap_or(std::cmp::Ordering::Less));

Or by checking if a given argument contains a NaN in the first place if NaN breaks further work. I think having one of these and returning None is preferable to a panic inside the method. At the very least this behavior should be documented.

@mourner mourner added the bug Something isn't working label Apr 22, 2019
@mourner
Copy link
Owner

mourner commented Mar 21, 2023

Fixed by #28

@mourner mourner closed this as completed Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants