mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
gamma.hpp
Go to the documentation of this file.
1 /** \file gamma.hpp
2  * \brief Declares and defines the gamma function.
3  * \ingroup gen_math_files
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  */
7 
8 //***********************************************************************//
9 // Copyright 2020 Jared R. Males (jaredmales@gmail.com)
10 //
11 // This file is part of mxlib.
12 //
13 // mxlib is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // mxlib is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 //***********************************************************************//
26 
27 #ifndef mx_gamma_hpp
28 #define mx_gamma_hpp
29 
30 #include <type_traits>
31 
32 #ifdef MX_INCLUDE_BOOST
33 #include <boost/math/special_functions/gamma.hpp>
34 #endif
35 
36 namespace mx
37 {
38 namespace math
39 {
40 namespace func
41 {
42 
43 /// The Gamma Function
44 /** This is a wrapper for boost.
45  *
46  * \tparam T a real floating point type
47  *
48  * \returns the value of the Gamma Function.
49  *
50  * \ingroup gen_math_gamma
51  */
52 template<typename T>
53 T tgamma( T x /**< [in] the argument of the gamma function*/ )
54 {
55 #ifdef MX_INCLUDE_BOOST
56  return boost::math::tgamma<T>(x);
57 #else
58  static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value, "tgamma<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
59  return 0;
60 #endif
61 }
62 
63 template<>
64 float tgamma<float>( float x);
65 
66 template<>
67 double tgamma<double>( double x );
68 
69 template<>
70 long double tgamma<long double>( long double x );
71 
72 #ifdef HASQUAD
73 template<>
74 __float128 tgamma<__float128>( __float128 x );
75 #endif
76 
77 }
78 }
79 }
80 
81 #endif //mx_gamma_hpp
T tgamma(T x)
The Gamma Function.
Definition: gamma.hpp:53
The mxlib c++ namespace.
Definition: mxError.hpp:107