41template <
typename FloatingType>
60 Polynomial (
const FloatingType* coefficients,
int numCoefficients)
61 : coeffs (coefficients, numCoefficients)
82 template <
typename... Values>
101 for (
int i = coeffs.
size(); --i >= 0;)
110 return coeffs.
size() - 1;
119 for (
auto& c : result.coeffs)
128 if (coeffs.
size() < other.coeffs.
size())
133 for (
int i = 0; i < other.coeffs.
size(); ++i)
134 result[i] += other[i];
145 auto N1 = coeffs.
size();
146 auto N2 = other.coeffs.
size();
147 auto Nmax = jmax (N1, N2);
149 auto N = N1 + N2 - 1;
151 for (
int i = 0; i < N; ++i)
153 FloatingType value (0);
155 for (
int j = 0; j < Nmax; ++j)
156 if (j >= 0 && j < N1 && i - j >= 0 && i - j < N2)
157 value = value + (*this)[j] * other[i - j];
159 result.coeffs.
add (value);
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
int size() const noexcept
Returns the current number of elements in the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
A class representing a polynomial.
Polynomial & operator=(const Polynomial &)=default
Creates a copy of another polynomial.
Polynomial(Values... items)
Creates a new polynomial with coefficients by a C++11 initializer list.
Polynomial()
Creates a new polynomial which will always evaluate to zero.
FloatingType operator[](int index) const noexcept
Returns a single coefficient of the receiver for reading.
Polynomial(const Polynomial &)=default
Creates a copy of another polynomial.
Polynomial< FloatingType > getSumWith(const Polynomial< FloatingType > &other) const
Returns the sum of this polynomial with another.
Polynomial< FloatingType > withGain(double gain) const
Returns the polynomial with all its coefficients multiplied with a gain factor.
Polynomial(const FloatingType *coefficients, int numCoefficients)
Creates a new polynomial with given coefficients.
Polynomial< FloatingType > getProductWith(const Polynomial< FloatingType > &other) const
computes the product of two polynomials and return the result
Polynomial(Polynomial &&)=default
Creates a copy of another polynomial.
int getOrder() noexcept
Returns the order of the polynomial.
FloatingType operator()(FloatingType x) const noexcept
Evaluates the value of the polynomial at a single point x.