HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
math.hpp
Go to the documentation of this file.
1 #ifndef _MATH_HPP
2 #define _MATH_HPP
3 
4 #include <cmath>
5 
6 namespace Math
7 {
9 
10  inline constexpr double PI = M_PI;
11 
12  inline const size_t factorial(size_t n)
13  {
14  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
15  }
16 
17  inline const size_t nChoosek(size_t n, size_t k)
18  {
19  if (k > n)
20  {
21  return 0;
22  }
23  if (k * 2 > n)
24  {
25  k = n - k;
26  }
27  if (k == 0)
28  {
29  return 1;
30  }
31 
32  size_t result = n;
33  for (size_t i = 2; i <= k; ++i)
34  {
35  result *= (n - i + 1);
36  result /= i;
37  }
38  return result;
39  }
40 
41  template <typename T>
42  const int sgn(T val)
43  {
44  return (T(0) < val) - (val < T(0));
45  }
46 
47  // branch -1: -2\pi < \theta \le 0
48  // branch 0: -\pi < \theta \le \pi
49  // branch 1: 0 \le \theta < 2\pi
50  inline double atan2(double y, double x, int branch = 0)
51  {
52  double val = (((x != 0) || (y != 0)) ? std::atan2(y, x) : 0.0);
53  if (branch == 1)
54  {
55  if (y < 0)
56  {
57  val += 2.0 * PI;
58  }
59  }
60  if (branch == -1)
61  {
62  if (y > 0)
63  {
64  val -= 2.0 * PI;
65  }
66  else if ((y == 0) && (x < 0))
67  {
68  val -= 2.0 * PI;
69  }
70  }
71  return val;
72  }
73 }
74 
75 #endif
Compute max and min eigenvalues of all matrices for i
Definition: compute_eigs.m:5
if(strcmp(field, 'real')) % real valued entries T
Definition: mmread.m:93
Definition: math.hpp:7
const int sgn(T val)
Definition: math.hpp:42
double atan2(double y, double x, int branch=0)
Definition: math.hpp:50
const size_t nChoosek(size_t n, size_t k)
Definition: math.hpp:17
const size_t factorial(size_t n)
Definition: math.hpp:12
constexpr double PI
Free math functions and global variables ///.
Definition: math.hpp:10