#partial-eq #eq #f32 #f64 #hash

float-derive

A crate that allows deriving Eq and Hash for types that contain floating points

1 unstable release

0.1.0 Oct 29, 2022

#2112 in Rust patterns

Download history 1120/week @ 2024-07-22 1012/week @ 2024-07-29 813/week @ 2024-08-05 1126/week @ 2024-08-12 1115/week @ 2024-08-19 667/week @ 2024-08-26 1034/week @ 2024-09-02 702/week @ 2024-09-09 1277/week @ 2024-09-16 1153/week @ 2024-09-23 1300/week @ 2024-09-30 1387/week @ 2024-10-07 781/week @ 2024-10-14 1765/week @ 2024-10-21 1428/week @ 2024-10-28 1561/week @ 2024-11-04

5,552 downloads per month

MIT/Apache

6KB

⚡ float-derive

A crate that allows deriving Eq and Hash for types that contain floats 🦀

crates license dependency-status

[dependencies]
float-derive = "0.1.0"
IEEE 754 floating point numbers can have the value NAN (not a number). It is unequal to any float, including itself! This is the reason `f32` and `f64` doesn’t implement the `Eq` trait.

This crate allows to derive Eq and Hash for traits that contain floating points by explicitly comparing floating points such that: NAN == NAN is true.

How to use

use float_derive::{FloatPartialEq, FloatEq, FloatHash};

#[derive(FloatPartialEq, FloatEq, FloatHash)]
struct MyStruct {
    a: i32,
    b: i32,
    my_float: f32,
    my_second_float: f64
}

#[derive(FloatPartialEq, FloatEq, FloatHash)]
enum MyEnum {
    A(i32, f32),
    B { a: i32, b: f64 },
    C
}

Credits

Dependencies

~2MB
~42K SLoC