brendanzab/approx

less than or equal to

Closed this issue · 0 comments

This line:

ulps_eq.rs:61

                $U::abs(int_self - int_other) < max_ulps as $U

uses strictly less than. However I'd like to make the argument for using <=, and also point out that it will change the behavior and should come with a version bump.

In the randomascii article, he uses <= exclusively throughout. He comments about it in the comments below the article: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/#li-comment-8342

Also, the similar lines of logic elsewhere in the crate use <= such as abs_diff_eq.rs and relative_eq using <= epsilon

If you use <, then anyone trying to do a comparison with max_ulps=0 and thinking this means the numbers must be exactly equal, would be suprised to see two exactly equal numbers coming out as not equal (because no absolute value is less than zero). At the interface of the crate, however, this doesn't happen because the epsilon based comparsion kicks in and overrides.