I want to create HashSetfor real numbers (currently Doubles) using a certain tolerance ( epsilon), (cf Since use only works for exact equality, and this is the last class, I cannot use it. My initial idea is to extend (for example, before ), using the method and create a new class where it uses this value from .. However, I would like to check if existing solutions and existing F / OSS libraries exist.Assert.assertEquals(double, double, double)
Double.equals()DoubleHashSetDoubleHashSetsetEpsilon(double)ComparableDoubleequals()DoubleHashSet
(In the future I will want to extend this to tuples of real numbers - for example, rectangles and cubes - so the preferred general approach is
NOTE. @NPE suggested that this is not possible. Unfortunately, I suspect that this is formally correct :-) So I wonder if there are approximate methods ... Others must have had this problem and it was solved approximately. (I already use the tool regularly Real.isEqual(a, b, epsilon), and it is very useful.) I am ready to accept some infrequent transitivity errors.
NOTE. I will use TreeSet as it solves the problem of "almost equals ()". Later I will compare complexNumbers, rectangles (and more complex objects), and it is really useful to set a limit within which 2 things are equal. There is no simple natural ordering of complexNumbers (perhaps Cantor’s work will work), but we can tell how nearly they are equal.