preCICE
Loading...
Searching...
No Matches
differences.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <cstdlib>
5
6namespace precice::math {
7
8constexpr double NUMERICAL_ZERO_DIFFERENCE = 1.0e-14;
9
11template <class DerivedA, class DerivedB>
12constexpr bool equals(const Eigen::MatrixBase<DerivedA> &A,
13 const Eigen::MatrixBase<DerivedB> &B,
14 double tolerance = NUMERICAL_ZERO_DIFFERENCE)
15{
16 return A.isApprox(B, tolerance);
17}
18
20inline bool equals(double a, double b, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
21{
22 auto d = std::abs(a - b);
23 auto scale = std::max(1.0, std::max(std::abs(a), std::abs(b)));
24 return d <= tolerance * scale;
25}
26
27inline bool isZero(double a, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
28{
29 return std::abs(a) < tolerance;
30}
31
32inline bool greater(double a, double b, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
33{
34 return a > b + tolerance;
35}
36
37inline bool greaterEquals(double a, double b, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
38{
39 return (a > b) || ::precice::math::equals(a, b, tolerance);
40}
41
42inline bool smaller(double a, double b, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
43{
44 return a + tolerance < b;
45}
46
47inline bool smallerEquals(double a, double b, double tolerance = NUMERICAL_ZERO_DIFFERENCE) noexcept
48{
49 return (a < b) || ::precice::math::equals(a, b, tolerance);
50}
51
52} // namespace precice::math
provides general mathematical constants and functions.
Definition barycenter.cpp:9
bool smallerEquals(double a, double b, double tolerance=NUMERICAL_ZERO_DIFFERENCE) noexcept
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
bool greaterEquals(double a, double b, double tolerance=NUMERICAL_ZERO_DIFFERENCE) noexcept
bool greater(double a, double b, double tolerance=NUMERICAL_ZERO_DIFFERENCE) noexcept
constexpr double NUMERICAL_ZERO_DIFFERENCE
bool isZero(double a, double tolerance=NUMERICAL_ZERO_DIFFERENCE) noexcept
bool smaller(double a, double b, double tolerance=NUMERICAL_ZERO_DIFFERENCE) noexcept