34template <
typename FloatingType>
53 Polynomial (
const FloatingType* coefficients,
int numCoefficients)
54 : coeffs (coefficients, numCoefficients)
75 template <
typename... Values>
94 for (
int i = coeffs.
size(); --i >= 0;)
103 return coeffs.
size() - 1;
112 for (
auto& c : result.coeffs)
121 if (coeffs.
size() < other.coeffs.
size())
126 for (
int i = 0; i < other.coeffs.
size(); ++i)
127 result[i] += other[i];
138 auto N1 = coeffs.
size();
139 auto N2 = other.coeffs.
size();
140 auto Nmax =
jmax (N1, N2);
142 auto N = N1 + N2 - 1;
144 for (
int i = 0; i < N; ++i)
146 FloatingType value (0);
148 for (
int j = 0; j < Nmax; ++j)
149 if (j >= 0 && j < N1 && i - j >= 0 && i - j < N2)
150 value = value + (*this)[j] * other[i - j];
152 result.coeffs.
add (value);
Holds a resizable array of primitive or copy-by-value objects.
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.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.