assert-eq-float 0.1.5

This crate provides the `assert_eq_float!` macros that support floats.
Documentation
/*!
# assert-eq-float

This crate provides the `assert_eq_float!` macros that support floats.

## Examples

```rust
use assert_eq_float::*;

assert_eq_float!(1.1 + 0.1, 1.2);       // error = 0.0000000000000021316282072803005
assert_eq_float!(1e100 + 2e100, 3e100); // error = 53290705182007510000000000000000000000000000000000000000000000000000000000000000000000

// other macros
debug_assert_eq_float!(0.0, 0.0);
assert_ne_float!(0.0, 0.1);
debug_assert_ne_float!(0.0, 0.1);
```

The default margin of error is dynamically computed by properties of IEEE 754 floating point numbers. You don't need to worry about it if you just want to check two float values are **equal**.
*/

#![no_std]

mod eq;
mod ne;

#[doc(hidden)]
pub trait FloatExt: Copy {
    fn abs(self) -> Self;
    fn __get_error(self, other: Self) -> Self;
}

impl FloatExt for f32 {
    #[inline]
    fn abs(self) -> Self {
        f32::abs(self)
    }

    #[inline]
    fn __get_error(self, other: Self) -> Self {
        // See: https://magiclen.org/float-precision/
        self.abs().min(other.abs()) * f32::EPSILON * 8.0
    }
}

impl FloatExt for f64 {
    #[inline]
    fn abs(self) -> Self {
        f64::abs(self)
    }

    #[inline]
    fn __get_error(self, other: Self) -> Self {
        // See: https://magiclen.org/float-precision/
        self.abs().min(other.abs()) * f64::EPSILON * 8.0
    }
}

#[doc(hidden)]
#[inline]
pub fn get_error<T: FloatExt>(a: T, b: T) -> T {
    a.__get_error(b)
}