#eq #ord #f32 #f64 #hash

no-std totally-ordered

No dependency, no-std totally ordered f32/f64

3 unstable releases

0.2.0 Dec 4, 2021
0.1.1 Feb 12, 2020
0.1.0 Feb 4, 2020

#1496 in Rust patterns

30 downloads per month

MIT license

14KB
199 lines

Totally Ordered IEEE Float Comparison for Rust

crates.io docs.rs Rust

This crate adds the TotallyOrderable trait for f32 and f64 values as well as the ABI-transparent TotallyOrdered type which adds Ord + Eq + Hash to wrapped floating point values. Main use case: sorting of floating-point arrays which may or may not contain not-a-numbers, infinities, and positive or negative zeros.

use totally_ordered::TotallyOrdered;
let mut values : [f64; 4] = [-0.0, 0.0, -1.0, 1.0];
TotallyOrdered::new_slice_mut(&mut values).sort();

lib.rs:

This crate adds the TotallyOrderable trait for f32 and f64 values as well as the ABI-transparent TotallyOrdered type which adds Ord + Eq + Hash to wrapped floating point values. Main use case: sorting of floating-point arrays which may or may not contain not-a-numbers, infinities, and positive or negative zeros.

use totally_ordered::TotallyOrdered;
let mut values : [f64; 4] = [-0.0, 0.0, -1.0, 1.0];
TotallyOrdered::new_slice_mut(&mut values).sort();

No runtime deps