JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Add FloatCloseTo matcher and refactor *CloseTo matchers

Open laz2 opened this issue 3 years ago • 0 comments

Updated pull request #226.

Changes:

  • Create base class BaseCloseTo for all closeTo matchers
  • Add FloatCloseTo matcher
  • Rename IsCloseTo matcher to DoubleCloseTo
  • Change error message for excluding errors in additional floating calculations (May user catch this error even with doubles?)

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

laz2 avatar Apr 20 '22 11:04 laz2