specfem::utilities::is_close

template<typename T>
bool specfem::utilities::is_close(const T &a, const T &b, const T &rel_tol = static_cast<T>(1e-6), const T &abs_tol = static_cast<T>(1e-7))

Check if two values are close within a tolerance.

This function checks whether two values are considered “close” to each other within specified tolerances. The comparison uses both relative and absolute tolerances to handle both large and small numbers appropriately.

Template Parameters:

T – Type of values to compare. Must support arithmetic operations.

Parameters:
  • a – First value to compare.

  • b – Second value to compare.

  • rel_tol – Relative tolerance for comparison (default: 1e-6).

  • abs_tol – Absolute tolerance for comparison (default: 1e-7).

Returns:

bool True if values are considered close according to the formula: |a - b| <= abs_tol + rel_tol * max(|a|, |b|) For simd types, returns true only if all lanes meet the condition.

template<typename T, typename U, typename = std::enable_if_t<!std::is_same<T, U>::value>>
bool specfem::utilities::is_close(const T &a, const U &b)