24#include "AstUtil/StringView.hpp"
43AST_UTIL_API errc_t
aParsePolynomial(StringView content, StringView varname, std::vector<double>& coeffs);
50AST_UTIL_API errc_t
aParsePolynomial(StringView content, std::vector<double>& coeffs);
57AST_UTIL_API std::string
aFormatPolynomial(
const std::vector<double>& coeffs, StringView varname);
65 Polynomial(
const std::initializer_list<double>& init)
96 const std::vector<double>& coeffs()
const {
return coeffs_; }
97 std::vector<double>& coeffs() {
return coeffs_; }
98 void setCoeffs(
const std::vector<double>& coeffs){ coeffs_ = coeffs; }
99 void setCoeffs(std::vector<double>&& coeffs){ coeffs_ = std::move(coeffs); }
104 double eval(
double x)
const;
106 std::vector<double> coeffs_;
111inline double Polynomial::eval(
double x)
const
113 if(coeffs_.size() == 0){
116 else if(coeffs_.size() == 1)
122 double temp = coeffs_.back();
123 for (
int i = (
int)coeffs_.size() - 2; i >= 0; --i) {
133 return poly.
parse(content);
136A_ALWAYS_INLINE errc_t aParsePolynomial(StringView content, StringView varname, Polynomial& poly)
138 return poly.parse(content, varname);
std::string toString(StringView varname)
将多项式表达式转换为字符串
定义 Polynomial.hpp:91
errc_t parse(StringView content, StringView varname)
解析多项式表达式
定义 Polynomial.hpp:77
errc_t parse(StringView content)
解析多项式表达式(默认变量名 "x")
定义 Polynomial.hpp:84
std::string aFormatPolynomial(const std::vector< double > &coeffs, StringView varname)
将系数向量格式化为多项式表达式字符串
定义 Polynomial.cpp:180
errc_t aParsePolynomial(StringView content, StringView varname, std::vector< double > &coeffsOut)
解析多项式表达式
定义 Polynomial.cpp:30