Loading...
Searching...
No Matches
poly.h
Go to the documentation of this file.
1#ifndef _BBM_POLY_H_
2#define _BBM_POLY_H_
3
4/************************************************************************/
5/*! \file poly.h
6 \brief Compile time polynomial using Horner's method.
7*************************************************************************/
8
9namespace bbm {
10
11 /*** Implementation details ***/
12 namespace detail {
13
14 template<size_t MAXN, typename T, typename T0, typename... Ts>
15 inline constexpr auto poly(T&& x, T0&& c0, Ts&&... c)
16 {
17 if constexpr (MAXN == 1 || sizeof...(Ts) == 0) return c0;
18 else return poly<MAXN-1>(std::forward<T>(x), std::forward<Ts>(c)...)*x + c0;
19 }
20
21 } // end detail namespace
22
23
24 /**********************************************************************/
25 /*! \brief Compute a polynomial \f$ p(x) = \sum_{i=0} x^i * c_i \f$
26
27 \param x = value to evaluate the polynomial at
28 \param c0 = constant coefficient
29 \param c... = remainder of coefficients.
30 \returns the evaluation of the polynomial
31
32 Determins the max degree based on the number of coefficients.
33 ***********************************************************************/
34 template<typename T, typename T0, typename... Ts>
35 inline constexpr auto poly(T&& x, T0&& c0, Ts&&... c)
36 {
37 return bbm::detail::poly<sizeof...(Ts)+1>(std::forward<T>(x), std::forward<T0>(c0), std::forward<Ts>(c)...);
38 }
39
40
41 /**********************************************************************/
42 /*! \brief Compute a polynomial \f$ p(x) = \sum_{i=0}^N x^i * c_i \f$
43
44 \tparam N = max polynomial degree
45 \param x = value to evaluate the polynomial at
46 \param c0 = constant coefficient
47 \param c... = remainder of coefficients.
48 \returns the evaluation of the polynomial
49
50 Will only evaluate the coefficients less than max degree+1.
51 ***********************************************************************/
52 template<size_t N, typename T, typename T0, typename... Ts>
53 inline constexpr auto poly(T&& x, T0&& c0, Ts&&... c)
54 {
55 return bbm::detail::poly<N>(std::forward<T>(x), std::forward<T0>(c0), std::forward<Ts>(c)...);
56 }
57
58} // end bbm namespace
59
60#endif /* _BBM_POLY_H_ */
constexpr decltype(auto) x(bbm::vec3d< T > &v)
Definition: vec.h:20
Definition: aggregatebsdf.h:29
constexpr auto poly(T &&x, T0 &&c0, Ts &&... c)
Compute a polynomial .
Definition: poly.h:35