source: src/base/polynomial.hpp@ d24c2f

Last change on this file since d24c2f was dfed1c, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Major vmg update.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1136 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * @file polynomial.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Nov 21 13:26:56 2011
5 *
6 * @brief Class to represent and evaluate a polynomial.
7 *
8 */
9
10#ifndef POLYNOMIAL_HPP_
11#define POLYNOMIAL_HPP_
12
13#include <cstdarg>
14#include <vector>
15
16namespace VMG
17{
18
19class Polynomial
20{
21public:
22 Polynomial()
23 {}
24
25 Polynomial(const int& degree,...)
26 {
27 va_list vl;
28 coeff.resize(degree+1);
29 va_start(vl, degree);
30 for (int i=0; i<=degree; ++i)
31 coeff[i] = va_arg(vl, vmg_float);
32 va_end(vl);
33 }
34
35 Polynomial(const Polynomial& rhs)
36 {
37 coeff.resize(rhs.coeff.size());
38 for (unsigned int i=0; i<coeff.size(); ++i)
39 coeff[i] = rhs.coeff[i];
40 }
41
42 vmg_float operator()(const vmg_float& val) const
43 {
44 double result = coeff.back();
45 for (int i=coeff.size()-2; i>=0; --i)
46 result = coeff[i] + result * val;
47 return result;
48 }
49
50 Polynomial& operator=(const Polynomial& rhs)
51 {
52 coeff.resize(rhs.coeff.size());;
53 for (unsigned int i=0; i<coeff.size(); ++i)
54 coeff[i] = rhs.coeff[i];
55
56 return *this;
57 }
58
59private:
60 std::vector<vmg_float> coeff;
61};
62
63}
64
65#endif /* POLYNOMIAL_HPP_ */
Note: See TracBrowser for help on using the repository browser.