Developer documentation
Version 3.0.3-105-gd3941f44
polynomial.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17
18#include "math/math.h"
19
20namespace MR
21{
22 namespace Math
23 {
24
25
27 template <class Cont>
28 default_type polynomial (Cont& coeffs, const default_type x)
29 {
30 if (!coeffs.size())
31 return NaN;
32 default_type result = coeffs[coeffs.size()-1];
33 for (ssize_t i = coeffs.size() - 2; i >= 0; --i) {
34 result *= x;
35 result += default_type(coeffs[i]);
36 }
37 return result;
38 }
39
40
41
42 }
43}
44
default_type polynomial(Cont &coeffs, const default_type x)
Evaluate a polynomial expansion for a scalar term.
Definition: polynomial.h:28
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
constexpr default_type NaN
Definition: types.h:230