Announcing `float_eq`, for explicitly bounded comparison of floating point numbers


I've just published version 0.2.0 of float_eq for comparing floating point values.

The crate provides absolute epsilon (abs), relative epsilon (rel) and Units in the Last Place (ulps) based boolean comparisons. These may be applied individually or chained together:

assert!(float_eq!(1000.0_f32, 1000.0002, ulps <= 4));

const ROUNDING_ERROR: f32 = 0.00034526698;
assert!(float_ne!(4.0_f32, 4.1, rel <= ROUNDING_ERROR));

It has asserts that share the same interface:

const RECIP_REL_EPSILON: f32 = 0.00036621094;
let recip = 0.1_f32.recip();
assert_float_eq!(recip, 10.0, rel <= RECIP_REL_EPSILON);

assert_float_ne!(0.0_f32, 0.0001, abs <= 0.00005, ulps <= 4);

And finally, it provides traits that may be implemented to extend this functionality over user types.

I realise that there are a bunch of existing crates which provide these kinds of features, but they often assume default bounds on their checks or implicitly prefer particular algorithms. Instead, I wanted to explore building an API that exposes the inherent complexity in a terse way and document it in a manner that hopefully guides users to make informed choices when choosing and parameterising the types of comparison they need. The API docs explain in more detail.

I am fairly new to Rust, and this is my first published crate. I have to say that coming from a background of writing low level C++ libraries, I am honestly very impressed by the Rust dev ecosystem. Using cargo,, travis-ci and the code coverage tools has been very straightforward and the community seems like a friendly place to be.

Constructive criticism and suggestions appreciated, I hope you're having a lovely day :slight_smile: