27#ifndef vtkMathUtilities_h
28#define vtkMathUtilities_h
40bool FuzzyCompare(A a, A b, A epsilon = std::numeric_limits<A>::epsilon())
42 return fabs(a - b) < epsilon;
52 if ((b <
static_cast<A
>(1)) && (a > b * std::numeric_limits<A>::max()))
54 return std::numeric_limits<A>::max();
58 if ((a ==
static_cast<A
>(0)) ||
59 ((b >
static_cast<A
>(1)) && (a < b * std::numeric_limits<A>::min())))
61 return static_cast<A
>(0);
73bool NearlyEqual(A a, A b, A tol = std::numeric_limits<A>::epsilon())
75 A absdiff = fabs(a - b);
76 A d1 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(a));
77 A d2 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(b));
79 return ((d1 <= tol) || (d2 <= tol));
bool NearlyEqual(A a, A b, A tol=std::numeric_limits< A >::epsilon())
A slightly different fuzzy comparator that checks if two values are "nearly" equal based on Knuth,...
A SafeDivision(A a, A b)
Performs safe division that catches overflow and underflow.
bool FuzzyCompare(A a, A b, A epsilon=std::numeric_limits< A >::epsilon())
Perform a fuzzy compare of floats/doubles, specify the allowed tolerance.