MLIB
Loading...
Searching...
No Matches
poly.h
Go to the documentation of this file.
1
#pragma once
8
#if __has_include("defs.h")
9
#include "defs.h"
10
#endif
11
12
#include <array>
13
#include <vector>
14
15
namespace
mlib {
16
17
template
<
typename
T>
28
T
poly
(T x,
const
T* coeff,
int
n)
29
{
30
T val = coeff[n - 1];
31
for
(
int
i = n - 2; i >= 0; i--)
32
{
33
val *= x;
34
val += coeff[i];
35
}
36
return
val;
37
}
38
49
template
<
typename
T,
size_t
N>
50
T
poly
(T x, std::array<T, N> coeff)
51
{
52
return
poly
(x, coeff.data (), (
int
)N);
53
}
54
63
template
<
typename
T>
64
T
poly
(T x, std::vector<T> coeff)
65
{
66
return
poly
(x, coeff.data (), (
int
)coeff.size ());
67
}
68
69
}
// namespace mlib
mlib::poly
T poly(T x, const T *coeff, int n)
Evaluate a polynomial using Horner's scheme.
Definition
poly.h:28
include
mlib
poly.h
Generated on Thu Dec 5 2024 19:00:30 for MLIB by
1.9.8