I am in no way an expert on this matter, so please be gentle with the following!
I've created this issue earlier: Cannot sort f64 · Issue #67417 · rust-lang/rust · GitHub
Complaining that the following does not work.
fn main() {
let fs = vec![11.0, 7.0, 5.0, 3.14, 3.0, 2.7182, 2.0, 1.4142, 9.8, 100.0, 10.0];
fs.sort();
}
but was directed here for "discussion". Now my opinion is that this should definitely work. My reasons are:
- The typical solution of using
sort_by
does not compose well. For example, slice - Rust cannot be used with a float output. - The argument that Inf and NaN cannot be compared is a straw man. We cannot take a square root of negative numbers either and yet that exists. Other examples are easy to find.
- Programming languages which cannot sort numbers are ridiculous. This sounds silly but actually seems accurate to me.
So, if somebody could explain to me why this behavior is very intentional (to quote a comment on the issue) I would be grateful.