hamcrest / JavaHamcrest

Java (and original) version of Hamcrest
http://hamcrest.org/
BSD 3-Clause "New" or "Revised" License
2.11k stars 379 forks source link

Add FloatCloseTo matcher and refactor *CloseTo matchers #385

Closed laz2 closed 4 months ago

laz2 commented 2 years ago

Updated pull request #226.

Changes:

PS. Example of error with additional floating calculations:

public static void main(String[] args) {
    var f = Math.abs(1.0f - 0.1f);
    System.out.println(f + " " + (f - 0.5f));
    var d = Math.abs(1.0d - 0.1d);
    System.out.println(d + " " + (d - 0.5d));
}

After run:

0.9 0.39999998
0.9 0.4