float-ord

Crates.iofloat-ord
lib.rsfloat-ord
version0.3.2
sourcesrc
created_at2017-03-24 17:30:26.280649
updated_at2021-07-27 15:40:28.462791
descriptionA total ordering for floating-point numbers
homepage
repositoryhttps://github.com/notriddle/rust-float-ord
max_upload_size
id9138
size21,860
Michael Howell (notriddle)

documentation

https://docs.rs/float-ord/0.3.1/float-ord/

README

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.

Commit count: 42

cargo fmt