#nan #total #order #wrapper #eq #float #setting

eq-float

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

1 unstable release

0.1.0 Dec 5, 2018

#1948 in Algorithms

Download history 425/week @ 2023-12-08 412/week @ 2023-12-15 55/week @ 2023-12-22 75/week @ 2023-12-29 300/week @ 2024-01-05 434/week @ 2024-01-12 267/week @ 2024-01-19 326/week @ 2024-01-26 185/week @ 2024-02-02 356/week @ 2024-02-09 361/week @ 2024-02-16 277/week @ 2024-02-23 253/week @ 2024-03-01 300/week @ 2024-03-08 398/week @ 2024-03-15 360/week @ 2024-03-22

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