30#ifndef vtkMathUtilities_h
31#define vtkMathUtilities_h
45bool FuzzyCompare(A a, A b, A epsilon = std::numeric_limits<A>::epsilon())
47 return fabs(a - b) < epsilon;
57 if ((b <
static_cast<A
>(1)) && (a > b * std::numeric_limits<A>::max()))
59 return std::numeric_limits<A>::max();
63 if ((a ==
static_cast<A
>(0)) ||
64 ((b >
static_cast<A
>(1)) && (a < b * std::numeric_limits<A>::min())))
66 return static_cast<A
>(0);
78bool NearlyEqual(A a, A b, A tol = std::numeric_limits<A>::epsilon())
80 A absdiff = fabs(a - b);
84 return ((d1 <= tol) || (d2 <= tol));
117 max0 = max0 < value ? value : max0;
119 else if (value > max0)
121 min0 = min0 > value ? value : min0;
128 typename std::enable_if<!std::is_floating_point<A>::value>::type* = 0)
135 typename std::enable_if<std::is_floating_point<A>::value>::type* = 0)
137 if (!std::isnan(value))
void UpdateRange(A &min0, A &max0, const A &value, typename std::enable_if<!std::is_floating_point< A >::value >::type *=0)
void UpdateRangeImpl(A &min0, A &max0, const A &value)
Update an existing min - max range with a new prospective value.
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.