#comparison #float #floating-point

is_close

Determine whether floating point numbers are close in value

4 releases

0.1.3 Jul 11, 2021
0.1.2 May 31, 2021
0.1.1 Oct 6, 2020
0.1.0 Oct 5, 2020

#443 in Testing

Download history 529/week @ 2024-03-13 692/week @ 2024-03-20 548/week @ 2024-03-27 431/week @ 2024-04-03 574/week @ 2024-04-10 666/week @ 2024-04-17 427/week @ 2024-04-24 302/week @ 2024-05-01 265/week @ 2024-05-08 438/week @ 2024-05-15 524/week @ 2024-05-22 408/week @ 2024-05-29 490/week @ 2024-06-05 638/week @ 2024-06-12 616/week @ 2024-06-19 484/week @ 2024-06-26

2,327 downloads per month
Used in cffdrs

MIT/Apache

20KB
292 lines

is_close

Determine whether floating point numbers are close in value

Build Status Crate API License Downloads

In scenarios such as testing it is often times more useful to know whether two floating point numbers are close to each other rather than exactly equal. Due to finite precision of computers, we usually cannot even expect bitwise equality of two values even if underlying math suggests it. This is where is_close comes into play. This crate is strongly inspired by Python PEP 485 aka math.isclose.

Usage

#[macro_use]
extern crate is_close;

assert!(is_close!(42.0, 42.0));
assert!(all_close!(vec![9.0, 10.0], vec![9.0, 10.0]));
assert!(any_close!(vec![0.0, 10.0], vec![9.0, 10.0]));

You'll find plenty of examples at our documentation.

License

Copyright © 2020 The promi Developers

is_close is licensed under MIT OR Apache 2.0 license

Dependencies

~155KB