Commit 3a61e2e227e1a0076c1b38babc43d24027a24b0a
1 parent
32da71ef
Add `inv_sqrt2pi` and `erfcc` to GMath
Showing
3 changed files
with
29 additions
and
0 deletions
include/GMath.hpp
| ... | ... | @@ -38,6 +38,7 @@ namespace gammalib { |
| 38 | 38 | const double pihalf = 1.570796326794896619231321691639751442099; |
| 39 | 39 | const double inv_pihalf = 0.6366197723675813430755350534900574; |
| 40 | 40 | const double inv_sqrt4pi = 0.2820947917738781434740397257803862929220; |
| 41 | + const double inv_sqrt2pi = 0.3989422804014327028632180827116826549172; | |
| 41 | 42 | const double pi2 = pi*pi; |
| 42 | 43 | const double deg2rad = 0.0174532925199432954743717; |
| 43 | 44 | const double rad2deg = 57.295779513082322864647722; |
| ... | ... | @@ -68,6 +69,7 @@ namespace gammalib { |
| 68 | 69 | |
| 69 | 70 | // Other functions |
| 70 | 71 | double gammln(const double& arg); |
| 72 | + double erfcc(const double& arg); | |
| 71 | 73 | double modulo(const double& v1, const double& v2); |
| 72 | 74 | } |
| 73 | 75 | ... | ... |
pyext/GMath.i
| ... | ... | @@ -37,6 +37,7 @@ namespace gammalib { |
| 37 | 37 | const double pihalf = 1.570796326794896619231321691639751442099; |
| 38 | 38 | const double inv_pihalf = 0.6366197723675813430755350534900574; |
| 39 | 39 | const double inv_sqrt4pi = 0.2820947917738781434740397257803862929220; |
| 40 | + const double inv_sqrt2pi = 0.3989422804014327028632180827116826549172; | |
| 40 | 41 | const double pi2 = pi*pi; |
| 41 | 42 | const double deg2rad = 0.0174532925199432954743717; |
| 42 | 43 | const double rad2deg = 57.295779513082322864647722; |
| ... | ... | @@ -67,5 +68,6 @@ namespace gammalib { |
| 67 | 68 | |
| 68 | 69 | // Other functions |
| 69 | 70 | double gammln(const double& arg); |
| 71 | + double erfcc(const double& arg); | |
| 70 | 72 | double modulo(const double& v1, const double& v2); |
| 71 | 73 | } | ... | ... |
src/numerics/GMath.cpp
| ... | ... | @@ -374,6 +374,31 @@ double gammalib::gammln(const double& arg) { |
| 374 | 374 | |
| 375 | 375 | |
| 376 | 376 | /***********************************************************************//** |
| 377 | + * @brief Computes complementary error function | |
| 378 | + * | |
| 379 | + * @param[in] arg Argument. | |
| 380 | + * @return Complementary error function. | |
| 381 | + * | |
| 382 | + * Reference: http://en.wikipedia.org/wiki/Complementary_error_function | |
| 383 | + ***************************************************************************/ | |
| 384 | +double gammalib::erfcc(const double& arg) { | |
| 385 | + /* (C) Copr. 1986-92 Numerical Recipes Software 0@.1Y.. */ | |
| 386 | + // Copied from Gaussian.cxx in the Fermi ScienceTools software | |
| 387 | + double t, z, ans; | |
| 388 | + | |
| 389 | + z = std::abs(arg); | |
| 390 | + t = 1.0/(1.0+0.5*z); | |
| 391 | + ans = t*std::exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+ | |
| 392 | + t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+ | |
| 393 | + t*(-0.82215223+t*0.17087277))))))))); | |
| 394 | + double result = arg >= 0.0 ? ans : 2.0-ans; | |
| 395 | + | |
| 396 | + // Return result | |
| 397 | + return result; | |
| 398 | +} | |
| 399 | + | |
| 400 | + | |
| 401 | +/***********************************************************************//** | |
| 377 | 402 | * @brief Returns the remainder of the division \a v1/v2. |
| 378 | 403 | * |
| 379 | 404 | * @param[in] v1 Argument 1. | ... | ... |