public class FuzzyFloat
extends java.lang.Object
Floating-point numbers are compared for equality by dividing them by one another and comparing the ratio. By default, they must be within 0.0001 (0.01%) to be considered equal.
Zero is never considered equal to a non-zero number, no matter how small its value.
Two NaN floats are not considered equal (consistent with the == operator).
| Modifier and Type | Class and Description |
|---|---|
class |
FuzzyFloat.DoubleArrayComparatorLexical
Lexically compares two double arrays.
|
| Constructor and Description |
|---|
FuzzyFloat()
Creates a FuzzyFloat with the default relativeRatio value of .0001.
|
FuzzyFloat(double relativeRatio)
Creates a FuzzyFloat.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
eq(double d1,
double d2)
Test d1 and d2 for equality using the current ratio.
|
boolean |
gt(double d1,
double d2)
test d1 and d2 for
d1 > d2. |
boolean |
gte(double d1,
double d2)
test d1 and d2 for d1 ≥ d2.
|
int |
indexOf(double[] a,
double elt)
Searches for the first occurrence of elt in a.
|
int |
indexOf(double[] a,
double[] sub)
Searches for the first subsequence of
a that matches sub elementwise. |
boolean |
isElemMatch(double[] a1,
double[] a2)
Determines whether or not a1 and a2 are set equivalent (contain only the same elements).
|
boolean |
isSubset(double[] smaller,
double[] bigger)
Determines whether smaller is a subset of bigger.
|
boolean |
lt(double d1,
double d2)
Test d1 and d2 for
d1 < d2. |
boolean |
lte(double d1,
double d2)
Test d1 and d2 for
d1 ≤ d2. |
boolean |
ne(double d1,
double d2)
Test d1 and d2 for non-equality using the current ratio.
|
void |
setRelativeRatio(double relativeRatio)
Set all the fields of this class.
|
public FuzzyFloat()
public FuzzyFloat(double relativeRatio)
relativeRatio - the relative diff to use; see setRelativeRatio(double)public void setRelativeRatio(@UnknownInitialization @Raw FuzzyFloat this,
double relativeRatio)
relativeRatio - the new relative diff to use; a number near zero (zero is also permitted,
which requires exact matching rather than permitting fuzzy matching)FuzzyFloat(double)@Pure
public boolean eq(double d1,
double d2)
Note that if one of the numbers if 0.0, then the other number must be less than the square of the fuzzy ratio. This policy accommodates roundoff errors in floating-point values.
d1 - the first value to compared2 - the second value to compare@Pure
public boolean ne(double d1,
double d2)
d1 - the first value to compared2 - the second value to compareeq(double, double)@Pure
public boolean lt(double d1,
double d2)
d1 < d2. If d1 is equal to d2 using the current ratio this returns
false.d1 - the first value to compared2 - the second value to compareeq(double, double)@Pure
public boolean lte(double d1,
double d2)
d1 ≤ d2. If d1 is equal to d2 using the current ratio, this
returns true.d1 - the first value to compared2 - the second value to compareeq(double, double)@Pure
public boolean gt(double d1,
double d2)
d1 > d2. IF d1 is equal to d2 using the current ratio, this returns
false.d1 - the first value to compared2 - the second value to compareeq(double, double)@Pure
public boolean gte(double d1,
double d2)
d1 - the first value to compared2 - the second value to compareeq(double, double)@Pure
public int indexOf(double[] a,
double elt)
eq(double, double) test.a - the array to searchelt - the element to search forArrayList.indexOf(java.lang.Object)@Pure
public int indexOf(double[] a,
double[] sub)
a that matches sub elementwise. Elements
of sub are considered to match elements of a if they pass the eq(double, double) test.a - the sequence to search insub - the sequence to search forArrayList.indexOf(java.lang.Object),
String.indexOf(java.lang.String)@Pure
public boolean isElemMatch(double[] a1,
double[] a2)
eq(double, double).
Note that this implementation is optimized for cases where the elements are actually the same, since it does a sort of both arrays before starting the comparisons.
a1 - the first set to comparea2 - the second set to compare@Pure
public boolean isSubset(double[] smaller,
double[] bigger)
eq(double, double).
Note that this implementation is optimized for cases where the elements are actually the same, since it does a sort of both arrays before starting the comparisons.
smaller - the possibly-smaller subsetbigger - the possibly-larger set