#approximate #testing #comparison

approx_eq

A macro for comparing equality of two values up to an arbitrary error in the *relative* difference

8 releases

0.1.8 Nov 1, 2020
0.1.7 Oct 28, 2020

#14 in #approximate

Download history 1085/week @ 2024-07-23 1044/week @ 2024-07-30 1171/week @ 2024-08-06 1366/week @ 2024-08-13 1181/week @ 2024-08-20 1037/week @ 2024-08-27 792/week @ 2024-09-03 603/week @ 2024-09-10 740/week @ 2024-09-17 889/week @ 2024-09-24 577/week @ 2024-10-01 704/week @ 2024-10-08 949/week @ 2024-10-15 840/week @ 2024-10-22 1056/week @ 2024-10-29 942/week @ 2024-11-05

4,029 downloads per month
Used in 90 crates (17 directly)

MIT/Apache

6KB
82 lines

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
}

No runtime deps