18#ifndef vtkMathUtilities_h
19#define vtkMathUtilities_h
21#include "vtkABINamespace.h"
32VTK_ABI_NAMESPACE_BEGIN
39bool FuzzyCompare(A a, A b, A epsilon = std::numeric_limits<A>::epsilon())
41 return fabs(a - b) < epsilon;
51 if ((b <
static_cast<A
>(1)) && (a > b * std::numeric_limits<A>::max()))
53 return std::numeric_limits<A>::max();
57 if ((a ==
static_cast<A
>(0)) ||
58 ((b >
static_cast<A
>(1)) && (a < b * std::numeric_limits<A>::min())))
60 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));
108 if constexpr (std::is_floating_point_v<A>)
118 max = std::max(
max, value);
120 else if (value >
max)
122 min = std::min(min, value);
135 if constexpr (std::is_floating_point_v<A>)
137 if (
VTK_UNLIKELY(std::isinf(value) || std::isnan(value)))
145 max = std::max(
max, value);
147 else if (value >
max)
149 min = std::min(min, 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.
void UpdateRange(A &min, A &max, const A &value)
Update an existing min - max range with a new prospective value.
void UpdateRangeFinite(A &min, A &max, const A &value)
Update an existing min - max range with a new prospective value.
bool FuzzyCompare(A a, A b, A epsilon=std::numeric_limits< A >::epsilon())
Perform a fuzzy compare of floats/doubles, specify the allowed tolerance NB: this uses an absolute to...
#define VTK_UNLIKELY(cond)