CbmRoot
Loading...
Searching...
No Matches
KfMath.h
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include <cstddef>
13
15{
19 constexpr size_t NofPolCoefficients(size_t N, size_t M)
20 {
21 return M == 1 ? N + 1 : (NofPolCoefficients(N, M - 1) * (M + N)) / M;
22 }
23
34 template<size_t N, typename T>
35 constexpr T Horner(const T* c, const T& x)
36 {
37 if constexpr (N == 0) {
38 return c[0];
39 }
40 else {
41 return Horner<N - 1, T>(c, x) * x + c[N];
42 }
43 }
44
74 template<size_t N, typename T, typename... Args>
75 constexpr T Horner(const T* c, const T& x1, Args... xI)
76 {
77 if constexpr (N == 0) {
78 return c[0];
79 }
80 else {
81 constexpr size_t M = sizeof...(Args) + 1;
82 constexpr size_t k = NofPolCoefficients(N - 1, M);
83 return Horner<N - 1, T>(c, x1, xI...) * x1 + Horner<N, T>(c + k, xI...);
84 }
85 }
86} // namespace cbm::algo::kf::math
constexpr size_t NofPolCoefficients(size_t N, size_t M)
Number of coefficients in a polynomial.
Definition KfMath.h:19
constexpr T Horner(const T *c, const T &x)
Horner's scheme for a 1D-polynomial estimation.
Definition KfMath.h:35