#nan #order #total #wrapper #float #eq #ieee

eq-float

Float wrappers with a total order (by setting NAN == NAN)

1 unstable release

0.1.0 Dec 5, 2018

#12 in #total

Download history 203/week @ 2024-07-28 337/week @ 2024-08-04 279/week @ 2024-08-11 445/week @ 2024-08-18 403/week @ 2024-08-25 216/week @ 2024-09-01 219/week @ 2024-09-08 56/week @ 2024-09-15 146/week @ 2024-09-22 254/week @ 2024-09-29 329/week @ 2024-10-06 321/week @ 2024-10-13 348/week @ 2024-10-20 216/week @ 2024-10-27 197/week @ 2024-11-03 323/week @ 2024-11-10

1,086 downloads per month
Used in choose-rand

MIT license

7KB
164 lines

Eq-Float

Wrappers around rust floats that implement Eq by letting NAN == NAN be true. This lets you pretend there was a total order on floating point numbers. Use with care, this goes against the IEEE 754 standard.

Also implements Ord and Hash. The hash digest for positive and negative zero is identical, since 0.0 == -0.0. The hash digest for all NANs is also identical.

extern crate eq_float;

use eq_float::F32;

fn main() {
    assert!(!(std::f32::NAN == std::f32::NAN));
    assert!(F32(std::f32::NAN) == F32(std::f32::NAN));
    assert!(F32(std::f32::NAN) < F32(5.0));
}

No runtime deps