public static bool approx(double self, double that, Double tolerance)
{
// need this to check +inf, -inf, and nan
if (compare(self, new Double(that)) == 0) return true;
double t;
if (tolerance == null)
t = Math.Min(Math.Abs(self/1e6), Math.Abs(that/1e6));
else
t = tolerance.doubleValue();
return Math.Abs(self - that) <= t;
}