#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 212/week @ 2024-07-30 378/week @ 2024-08-06 337/week @ 2024-08-13 325/week @ 2024-08-20 430/week @ 2024-08-27 215/week @ 2024-09-03 191/week @ 2024-09-10 62/week @ 2024-09-17 213/week @ 2024-09-24 210/week @ 2024-10-01 330/week @ 2024-10-08 347/week @ 2024-10-15 328/week @ 2024-10-22 204/week @ 2024-10-29 220/week @ 2024-11-05 316/week @ 2024-11-12

1,136 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