I like (pseudo code, I don’t do java)
bool fuzzyEquals(double a, double b)
{
return abs(a - b) < eps * max(abs(a), abs(b));
}
with epsilon being a few times the machine epsilon. Take 10^-12 if you don’t know what to use.
This is quite problem dependant however. If the computations giving a and b are prone to roundoff error, or involve many operations, or are themselves within some (known) accuracy, you want to take a bigger epsilon.
Ths point is to use relative precision, not absolute.