approx_eq

Crates.ioapprox_eq
lib.rsapprox_eq
version0.1.8
sourcesrc
created_at2020-10-15 17:31:34.237117
updated_at2020-11-01 06:14:42.478564
descriptionA macro for comparing equality of two values up to an arbitrary error in the *relative* difference
homepage
repositoryhttps://github.com/al-jshen/approx_eq
max_upload_size
id300086
size6,626
Jeff Shen (al-jshen)

documentation

README

approx_eq

Build Status Crates.io Documentation

This crate provides a macro to check whether two numbers are approximately equal. It does so by checking that the relative difference between the two numbers is less than some upper limit.

To use this in your Rust program, add the following to your Cargo.toml file:

// Cargo.toml
[dependencies]
approx_eq = "0.1"

Using this macro is easy!

// main.rs
use approx_eq::assert_approx_eq;

fn main() {
  assert_approx_eq!(1., 0.99999999999); // should pass
  assert_approx_eq!(1., 0.99999999999, 1e-5); // should pass
  assert_approx_eq!(1., 0.99999999999, 1e-20); // should fail
  assert_approx_eq!(1., 2.) // should fail
}
Commit count: 24

cargo fmt