#floats #sort #compare

no-std float-ord

A total ordering for floating-point numbers

6 releases

Uses old Rust 2015

0.3.1 Apr 8, 2021
0.3.0 Apr 1, 2021
0.2.0 Jan 30, 2018
0.1.2 Jul 7, 2017
0.1.1 Mar 24, 2017

#44 in Rust patterns

Download history 3581/week @ 2020-12-25 5730/week @ 2021-01-01 5784/week @ 2021-01-08 6242/week @ 2021-01-15 5891/week @ 2021-01-22 5649/week @ 2021-01-29 5617/week @ 2021-02-05 6706/week @ 2021-02-12 7283/week @ 2021-02-19 5687/week @ 2021-02-26 5505/week @ 2021-03-05 6115/week @ 2021-03-12 5225/week @ 2021-03-19 6530/week @ 2021-03-26 5218/week @ 2021-04-02 7220/week @ 2021-04-09

25,135 downloads per month
Used in 97 crates (16 directly)

MIT/Apache

9KB
143 lines

Total ordering for floats

Build Status Crates.IO Documentation

A wrapper for floats that uses this ordering:

NaN | -Infinity | x < 0 | -0 | +0 | x > 0 | +Infinity | NaN

How does it work?

There is an old family magic spell that allows one to compare floating-point values without any floating-point work. Simply interpret the fp value as an unsigned integer, flip its sign bit (if positive) or all bits (if negative), and do the comparison normally.

The trick was developed on f32 and f64, but it should work on anything structured like the IEEE floats. Even the IEEE decimal formats.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps