float-derive

Crates.iofloat-derive
lib.rsfloat-derive
version0.1.0
sourcesrc
created_at2022-10-29 16:43:24.062411
updated_at2022-10-29 16:43:24.062411
descriptionA crate that allows deriving Eq and Hash for types that contain floating points
homepagehttps://github.com/projectkml/float-derive
repositoryhttps://github.com/projectkml/float-derive
max_upload_size
id701092
size3,975
BeastLe9enD (BeastLe9enD)

documentation

https://docs.rs/float-derive

README

⚡ 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

Commit count: 0

cargo fmt