GammaLib 2.0.0
Loading...
Searching...
No Matches
GMath.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GMath.hpp - Mathematical functions *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2012-2020 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GMath.hpp
23 * @brief Mathematical function definitions
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMATH_HPP
28#define GMATH_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <cmath>
32
33/* __ Constants __________________________________________________________ */
34namespace gammalib {
35 const double pi = 3.141592653589793238462643383279502884197;
36 const double twopi = 6.283185307179586476925286766559005768394;
37 const double fourpi = 12.56637061435917295385057353311801153679;
38 const double pihalf = 1.570796326794896619231321691639751442099;
39 const double inv_pihalf = 0.6366197723675813430755350534900574;
40 const double inv_sqrt4pi = 0.2820947917738781434740397257803862929220;
41 const double inv_sqrt2pi = 0.3989422804014327028632180827116826549172;
42 const double pi2 = pi*pi;
43 const double deg2rad = 0.0174532925199432954743717;
44 const double rad2deg = 57.295779513082322864647722;
45 const double ln2 = 0.6931471805599453094172321214581766;
46 const double ln10 = 2.3025850929940456840179914546843642;
47 const double inv_ln2 = 1.4426950408889634073599246810018921;
48 const double inv_ln10 = 1.0/ln10;
49 const double inv_loge = 1.0/std::log10(std::exp(1.0));
50 const double onethird = 1.0/3.0;
51 const double twothird = 2.0/3.0;
52 const double fourthird = 4.0/3.0;
53 const double sqrt_onehalf = std::sqrt(1.0/2.0);
54 const double sqrt_two = std::sqrt(2.0);
55 const double sqrt_pihalf = std::sqrt(pihalf);
56 const double sqrt_twopi = std::sqrt(twopi);
57}
58
59/* __ Prototypes _________________________________________________________ */
60namespace gammalib {
61
62 // Trigonometric functions
63 double acos(const double& arg);
64 double atan2(const double& y, const double& x);
65 double cosd(const double& angle);
66 double sind(const double& angle);
67 double tand(const double& angle);
68 double asind(const double& value);
69 double acosd(const double& value);
70 double atand(const double& value);
71 double atan2d(const double& y, const double& x);
72 void sincosd(const double& angle, double *s, double *c);
73
74 // Other functions
75 double gammln(const double& arg);
76 double erf(const double& arg);
77 double erfc(const double& arg);
78 double erfinv(const double& arg);
79 double modulo(const double& v1, const double& v2);
80 double plaw_integral(const double& x1,
81 const double& f1,
82 const double& x2,
83 const double& f2);
84 double gauss_integral(const double& x1, const double& x2);
85}
86
87#endif /* GMATH_HPP */
double angle(const GVector &a, const GVector &b)
Computes angle between vectors.
Definition GVector.cpp:974
double plaw_integral(const double &x1, const double &f1, const double &x2, const double &f2)
Returns the integral of a power law.
Definition GMath.cpp:566
double erfinv(const double &arg)
Computes inverse error function.
Definition GMath.cpp:463
const double onethird
Definition GMath.hpp:50
const double fourthird
Definition GMath.hpp:52
const double ln10
Definition GMath.hpp:46
void sincosd(const double &angle, double *s, double *c)
Compute sine and cosine of angle in degrees.
Definition GMath.cpp:342
const double pi2
Definition GMath.hpp:42
const double pi
Definition GMath.hpp:35
const double ln2
Definition GMath.hpp:45
const double inv_ln2
Definition GMath.hpp:47
const double sqrt_pihalf
Definition GMath.hpp:55
double erfc(const double &arg)
Computes complementary error function.
Definition GMath.cpp:450
const double pihalf
Definition GMath.hpp:38
double gammln(const double &arg)
Computes logarithm of gamma function.
Definition GMath.cpp:383
const double sqrt_twopi
Definition GMath.hpp:56
double erf(const double &arg)
Computes error function.
Definition GMath.cpp:417
double asind(const double &value)
Compute arc sine in degrees.
Definition GMath.cpp:250
const double deg2rad
Definition GMath.hpp:43
const double inv_pihalf
Definition GMath.hpp:39
double cosd(const double &angle)
Compute cosine of angle in degrees.
Definition GMath.cpp:134
const double sqrt_onehalf
Definition GMath.hpp:53
double sind(const double &angle)
Compute sine of angle in degrees.
Definition GMath.cpp:163
const double twothird
Definition GMath.hpp:51
const double sqrt_two
Definition GMath.hpp:54
double atan2(const double &y, const double &x)
Compute arc tangens in radians.
Definition GMath.cpp:102
double acos(const double &arg)
Computes acos by avoiding NaN due to rounding errors.
Definition GMath.cpp:69
const double fourpi
Definition GMath.hpp:37
const double inv_sqrt4pi
Definition GMath.hpp:40
double atan2d(const double &y, const double &x)
Compute arc tangens in degrees.
Definition GMath.cpp:308
double atand(const double &value)
Compute arc tangens in degrees.
Definition GMath.cpp:282
double acosd(const double &value)
Compute arc cosine in degrees.
Definition GMath.cpp:218
const double twopi
Definition GMath.hpp:36
double gauss_integral(const double &x1, const double &x2)
Returns the integral of a Gaussian function.
Definition GMath.cpp:605
const double inv_ln10
Definition GMath.hpp:48
const double inv_loge
Definition GMath.hpp:49
double modulo(const double &v1, const double &v2)
Returns the remainder of the division.
Definition GMath.cpp:526
const double inv_sqrt2pi
Definition GMath.hpp:41
const double rad2deg
Definition GMath.hpp:44
double tand(const double &angle)
Compute tangens of angle in degrees.
Definition GMath.cpp:192