Skip to content
Snippets Groups Projects
Commit eefc417c authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Merge branch 'fix/factorial' into 'master'

[math] Use integer type in Factorial

See merge request !1045
parents a1e068a4 d57c6a98
No related branches found
No related tags found
1 merge request!1045[math] Use integer type in Factorial
Pipeline #41217 passed
Pipeline: Dune Nightly Test

#41219

    ......@@ -2,6 +2,8 @@
    - Add `pragma omp simd` annotations in the LoopSIMD class to improve compiler optimizations
    - deprecate Factorial in common/math.hh (use factorial function)
    ## Build System
    - Remove the variable `DUNE_DEFAULT_LIBS`
    ......@@ -21,7 +23,6 @@
    - Remove deprecated cmake function overload `target_link_libraries`
    # Release 2.8
    - Set minimal required CMake version in cmake to >= 3.13.
    ......
    ......@@ -86,19 +86,20 @@ namespace Dune
    }
    //! Calculates the factorial of m at compile time
    //! \deprecated Will be removed after release 2.9
    template <int m>
    struct Factorial
    {
    //! factorial stores m!
    enum { factorial = m * Factorial<m-1>::factorial };
    static constexpr int factorial = m * Factorial<m-1>::factorial;
    };
    //! end of recursion of factorial via specialization
    template <>
    struct Factorial<0>
    struct [[deprecated("Use function factorial instead! Will be removed after Dune 2.9")]] Factorial<0>
    {
    // 0! = 1
    enum { factorial = 1 };
    static constexpr int factorial = 1;
    };
    ......
    ......@@ -26,12 +26,14 @@ auto testStaticFactorial (std::integral_constant<T, k> _k = {}) -> TestSuite
    {
    TestSuite t;
    std::cout << "test static factorial\n{";
    std::cout << "test factorial\n{";
    forEach(integralRange(_k), [&](auto _i) {
    auto value = Dune::factorial(_i);
    t.check(decltype(value)::value == Dune::Factorial<decltype(_i)::value>::factorial);
    const auto value = Dune::factorial(_i);
    const auto control = _i() == 0 ? 1 : _i() * Dune::factorial(_i() - 1);
    t.check( value() == control );
    std::cout<< ' ' << value() << ',';
    });
    ......@@ -46,17 +48,16 @@ auto testStaticBinomial (std::integral_constant<T, k> _k = {}) -> TestSuite
    {
    TestSuite t;
    std::cout << "test static binomial\n";
    std::cout << "test binomial\n";
    forEach(integralRange(_k), [&](auto _i) {
    std::cout << "{";
    forEach(integralRange(next(_i)), [&](auto _j) {
    const auto value = Dune::binomial(_i,_j);
    auto control = Dune::Factorial<decltype(_i)::value>::factorial
    / Dune::Factorial<decltype(_j)::value>::factorial
    / Dune::Factorial<decltype(_i)::value - decltype(_j)::value>::factorial;
    t.check(decltype(value)::value == control);
    const auto value = Dune::binomial(_i, _j);
    const auto control = Dune::factorial(_i) / ( Dune::factorial(_j) * Dune::factorial(_i() - _j()) );
    t.check( value() == control );
    std::cout<< ' ' << value() << ',';
    });
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment