BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Precomputed.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Math/Precomputed.h
6 //! @brief Defines namespace Math::Precomputed, providing precomputed constants
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_BASE_MATH_PRECOMPUTED_H
21 #define BORNAGAIN_BASE_MATH_PRECOMPUTED_H
22 
23 #include <array>
24 #include <utility>
25 #include <vector>
26 
27 namespace Math::internal {
28 
29 template <size_t N> struct ReciprocalFactorial {
30  static constexpr double value = ReciprocalFactorial<N - 1>::value / N;
31 };
32 
33 template <> struct ReciprocalFactorial<0> {
34  static constexpr double value = 1.0;
35 };
36 
37 template <template <size_t> class F, size_t... I>
38 constexpr std::array<double, sizeof...(I)> generateArrayHelper(std::index_sequence<I...>)
39 {
40  return {F<I>::value...};
41 };
42 
43 } // namespace Math::internal
44 namespace Math {
45 
46 //! Returns a compile-time generated std::array of reciprocal factorials.
47 
48 template <size_t N, typename Indices = std::make_index_sequence<N>>
49 constexpr std::array<double, N> generateReciprocalFactorialArray()
50 {
51  return internal::generateArrayHelper<internal::ReciprocalFactorial>(Indices{});
52 };
53 } // namespace Math
54 
55 #endif // BORNAGAIN_BASE_MATH_PRECOMPUTED_H
56 #endif // USER_API
constexpr complex_t I
Definition: Complex.h:21
constexpr std::array< double, sizeof...(I)> generateArrayHelper(std::index_sequence< I... >)
Definition: Precomputed.h:38
Various mathematical functions.
Definition: Bessel.h:26
constexpr std::array< double, N > generateReciprocalFactorialArray()
Returns a compile-time generated std::array of reciprocal factorials.
Definition: Precomputed.h:49
static constexpr double value
Definition: Precomputed.h:30