MLIB
Loading...
Searching...
No Matches
poly.h
Go to the documentation of this file.
1
/*
2
Copyright (c) Mircea Neacsu (2014-2025) Licensed under MIT License.
3
This file is part of MLIB project. See LICENSE file for full license terms.
4
*/
5
7
#pragma once
8
9
#if __has_include("defs.h")
10
#include "defs.h"
11
#endif
12
13
#include <array>
14
#include <vector>
15
16
namespace
mlib {
17
18
template
<
typename
T>
29
T
poly
(T x,
const
T* coeff,
int
n)
30
{
31
T val = coeff[n - 1];
32
for
(
int
i = n - 2; i >= 0; i--)
33
{
34
val *= x;
35
val += coeff[i];
36
}
37
return
val;
38
}
39
50
template
<
typename
T,
size_t
N>
51
T
poly
(T x, std::array<T, N> coeff)
52
{
53
return
poly
(x, coeff.data (), (
int
)N);
54
}
55
64
template
<
typename
T>
65
T
poly
(T x, std::vector<T> coeff)
66
{
67
return
poly
(x, coeff.data (), (
int
)coeff.size ());
68
}
69
70
}
// namespace mlib
mlib::poly
T poly(T x, const T *coeff, int n)
Evaluate a polynomial using Horner's scheme.
Definition
poly.h:29
include
mlib
poly.h
Generated on Wed Apr 23 2025 13:32:39 for MLIB by
1.13.0