mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
factorial.hpp
Go to the documentation of this file.
1 /** \file factorial.hpp
2  * \brief Declares and defines the factorial 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_factorial_hpp
28 #define mx_factorial_hpp
29 
30 #include <type_traits>
31 
32 #ifdef MX_INCLUDE_BOOST
33 #include <boost/math/special_functions/factorials.hpp>
34 #endif
35 
36 namespace mx
37 {
38 namespace math
39 {
40 namespace func
41 {
42 
43 /// The factorial function.
44 /**
45  * \ingroup functions
46  */
47 template<typename T>
48 T factorial( T x /**< [in] the argument */)
49 {
50 #ifdef MX_INCLUDE_BOOST
51  return boost::math::factorial<T>(x);
52 #else
53  static_assert(std::is_fundamental<T>::value || !std::is_fundamental<T>::value, "factorial<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost.");
54  return 0;
55 #endif
56 }
57 
58 template<>
59 float factorial<float>( float x);
60 
61 template<>
62 double factorial<double>( double x);
63 
64 template<>
65 long double factorial<long double>( long double x);
66 
67 #ifdef HASQUAD
68 template<>
69 __float128 factorial<__float128>( __float128 x);
70 #endif
71 
72 }
73 }
74 }
75 
76 #endif //mx_factorial_hpp
T factorial(T x)
The factorial function.
Definition: factorial.hpp:48
The mxlib c++ namespace.
Definition: mxError.hpp:107