MCPcopy Create free account
hub / github.com/Kitware/VTK / SafeDivision

Function SafeDivision

Common/Core/vtkMathUtilities.h:45–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 */
44template <class A>
45A SafeDivision(A a, A b)
46{
47 // Avoid overflow
48 if ((b < static_cast<A>(1)) && (a > b * std::numeric_limits<A>::max()))
49 {
50 return std::numeric_limits<A>::max();
51 }
52
53 // Avoid underflow
54 if ((a == static_cast<A>(0)) ||
55 ((b > static_cast<A>(1)) && (a < b * std::numeric_limits<A>::min())))
56 {
57 return static_cast<A>(0);
58 }
59
60 // safe to do the division
61 return (a / b);
62}
63
64/**
65 * A slightly different fuzzy comparator that checks if two values are

Callers 1

CheckValidityMethod · 0.50

Calls 2

maxFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected