Open smason opened 5 years ago
I'd be interested in this, too. I'm kind of a newbie Rustacean, but I wouldn't mind taking a stab at implementing or discussing this, either (mostly so I can learn something :smile:).
@cglosser https://lib.rs/crates/approx provides a macro for this as well as looking somewhat more popular
I've just started using your code and realised it doesn't have a concept of "relative difference", e.g:
will fail, even though the values are as close as possible to each other while being distinct. the hex representations of the above are:
i.e. one bit different, which seems like something I'd consider "approximately equal".
other libraries do something equivalent to:
where
rel_tol
andabs_tol
are configurable likeeps
is in your code, with your code implicitly using0
and1e-6
at the moment. for comparison, Python variously uses values of1e-9
and0
,1e-5
and1e-08
, and1e-7
and0
.could put a patch together, but not sure if this something you want & how much to break the existing API