MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / almostEqual

Function almostEqual

app/src/DSP.h:1314–1328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1312 */
1313template<Concepts::Numeric T>
1314[[nodiscard]] inline bool almostEqual(T a, T b, T relEps = T(1e-12), T absEps = T(1e-12)) noexcept
1315{
1316 if constexpr (std::floating_point<T>) {
1317 if (!std::isfinite(a) || !std::isfinite(b))
1318 return a == b;
1319 }
1320
1321 const T diff = std::abs(a - b);
1322
1323 if (diff <= absEps)
1324 return true;
1325
1326 const T scale = std::max(std::abs(a), std::abs(b));
1327 return diff <= relEps * scale;
1328}
1329
1330/**
1331 * @brief Explicit "not equal" companion to almostEqual().

Callers 7

notEqualFunction · 0.85
updateDataMethod · 0.85
padDerivedRangeMethod · 0.85
applyDerivedYBoundsMethod · 0.85
padDerivedRangeMethod · 0.85
applyAxisPaddingMethod · 0.85

Calls 3

TFunction · 0.85
isfiniteFunction · 0.85
absFunction · 0.85

Tested by

no test coverage detected