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

sort_unstable_by has no fallback to equal #27

Closed
AndriBaal opened this issue Mar 19, 2023 · 4 comments
Closed

sort_unstable_by has no fallback to equal #27

AndriBaal opened this issue Mar 19, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@AndriBaal
Copy link
Contributor

I use delaunator in a project of mine and sometimes on specific conditions the delaunator crashes because of the partial_cmp of 2 floats without a fallback. Specifically, this needs to be changed:

fn sortf(f: &mut [(usize, f64)]) {
    f.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap());
}

to:

fn sortf(f: &mut [(usize, f64)]) {
    f.sort_unstable_by(|&(_, da), &(_, db)| da.partial_cmp(&db).unwrap_or(core::cmp::Ordering::Equal));
}
@mourner mourner added the bug Something isn't working label Mar 20, 2023
@mourner
Copy link
Owner

mourner commented Mar 20, 2023

@AndriBaal nice catch! Would you mind making a PR with a fix + test?

@mourner
Copy link
Owner

mourner commented Mar 20, 2023

Looks like this would fix #9 too.

@AndriBaal
Copy link
Contributor Author

I have created a pull request, let me know if anything is missing. #28

@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