Version: SMASH-3.0
numerics.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2018,2020,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_NUMERICS_H_
11 #define SRC_INCLUDE_SMASH_NUMERICS_H_
12 
13 #include <cmath>
14 
15 #include "constants.h"
16 
26 namespace smash {
42 template <typename N>
43 bool almost_equal(const N x, const N y) {
44  return (std::abs(x - y) <= N(really_small) ||
45  std::abs(x - y) <=
46  N(0.5 * really_small) * (std::abs(x) + std::abs(y)));
47 }
62 template <typename N>
63 bool almost_equal_physics(const N x, const N y) {
64  return (std::abs(x - y) <= N(small_number) ||
65  std::abs(x - y) <=
66  N(0.5 * small_number) * (std::abs(x) + std::abs(y)));
67 }
68 
69 } // namespace smash
70 
71 #endif // SRC_INCLUDE_SMASH_NUMERICS_H_
Collection of useful constants that are known at compile time.
Definition: action.h:24
bool almost_equal_physics(const N x, const N y)
Same as smash::almost_equal, but for physical checks like energy-momentum conservation small_number i...
Definition: numerics.h:63
constexpr double small_number
Physical error tolerance.
Definition: constants.h:51
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:37
bool almost_equal(const N x, const N y)
Checks two numbers for relative approximate equality.
Definition: numerics.h:43