Comment

Comment by alextgordon

I too have suffered Rust's religiosity on the floating point issue.

In Python, given an array xs = [3.1, 1.2, 4.3, 2.2], I can write

    xs.sort()
and get [1.2, 2.2, 3.1, 4.4]

In Haskell

    sort xs
In Swift

    sort(&xs)
In Rust you have to spew this monstrosity

    xs.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Less))
The Rust position appears to be that sorting an array of floats is unreasonable and so you must be "punished" by not being allowed to use the built-in .sort() function.
parent alextgordon 11 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton