GM2Calc 2.3.0
Loading...
Searching...
No Matches
gm2_numerics.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef GM2_NUMERICS_HPP
20#define GM2_NUMERICS_HPP
21
22#include <cmath>
23#include <complex>
24#include <limits>
25
26namespace gm2calc {
27
28/// returns number squared
29template <typename T> T sqr(T x) noexcept { return x*x; }
30
31/// returns number to the third power
32template <typename T> T cube(T x) noexcept { return x*x*x; }
33
34/// returns number to the third power
35template <typename T> T pow3(T x) noexcept { return cube(x); }
36
37/// returns number to the 4th power
38template <typename T> T pow4(T x) noexcept { return sqr(sqr(x)); }
39
40/// returns square root of absolute of number
41double abs_sqrt(double) noexcept;
42
43/// returns sign of real number
44int sign(double) noexcept;
45
46/// returns square root of absolute of number, times sign
47double signed_abs_sqrt(double) noexcept;
48
49/// returns square of number, times sign
50double signed_sqr(double) noexcept;
51
52template <typename T>
53bool is_zero(T a, T eps) noexcept
54{
55 return std::fabs(a) < eps;
56}
57
58template <typename T>
59bool is_equal(T a, T b, T eps) noexcept
60{
61 return is_zero(a - b, eps);
62}
63
64template <typename T>
65bool is_equal_rel(T a, T b, T eps) noexcept
66{
67 const T max = std::max(std::abs(a), std::abs(b));
68 return is_zero(a - b, eps*(1.0 + max));
69}
70
71} // namespace gm2calc
72
73#endif
T pow4(T x) noexcept
returns number to the 4th power
double abs_sqrt(double x) noexcept
returns square root of absolute of number
T sqr(T x) noexcept
returns number squared
void svd_eigen(const Eigen::Matrix< Scalar, M, N > &m, Eigen::Array< Real,(((M)<(N)) ?(M) :(N)), 1 > &s, Eigen::Matrix< Scalar, M, M > *u, Eigen::Matrix< Scalar, N, N > *vh)
bool is_zero(const Eigen::ArrayBase< Derived > &a, double eps)
T pow3(T x) noexcept
returns number to the third power
T cube(T x) noexcept
returns number to the third power
int sign(double x) noexcept
returns sign of real number
bool is_equal_rel(T a, T b, T eps) noexcept
double signed_abs_sqrt(double x) noexcept
returns square root of absolute of number, times sign
bool is_equal(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< Derived > &b, double precision_goal)
double signed_sqr(double x) noexcept
returns square of number, times sign