LMMS
Loading...
Searching...
No Matches
juce_Polynomial.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28namespace dsp
29{
30
36template <typename FloatingType>
38{
39public:
40 //==============================================================================
43 {
44 coeffs.add (0);
45 }
46
55 Polynomial (const FloatingType* coefficients, int numCoefficients)
56 : coeffs (coefficients, numCoefficients)
57 {
58 jassert (! coeffs.isEmpty());
59 }
60
62 Polynomial (const Polynomial&) = default;
63
65 Polynomial (Polynomial&&) = default;
66
68 Polynomial& operator= (const Polynomial&) = default;
69
71 Polynomial& operator= (Polynomial&&) = default;
72
77 template <typename... Values>
78 Polynomial (Values... items) : coeffs (items...)
79 {
80 jassert (! coeffs.isEmpty());
81 }
82
83 //==============================================================================
85 FloatingType operator[] (int index) const noexcept { return coeffs.getUnchecked (index); }
86
88 FloatingType& operator[] (int index) noexcept { return coeffs.getReference (index); }
89
91 FloatingType operator() (FloatingType x) const noexcept
92 {
93 // Horner's method
94 FloatingType y (0);
95
96 for (int i = coeffs.size(); --i >= 0;)
97 y = (x * y) + coeffs.getUnchecked(i);
98
99 return y;
100 }
101
104 {
105 return coeffs.size() - 1;
106 }
107
108 //==============================================================================
111 {
112 auto result = *this;
113
114 for (auto& c : result.coeffs)
115 c *= gain;
116
117 return result;
118 }
119
122 {
123 if (coeffs.size() < other.coeffs.size())
124 return other.getSumWith (*this);
125
126 auto result = *this;
127
128 for (int i = 0; i < other.coeffs.size(); ++i)
129 result[i] += other[i];
130
131 return result;
132 }
133
136 {
138 result.coeffs.clearQuick();
139
140 auto N1 = coeffs.size();
141 auto N2 = other.coeffs.size();
142 auto Nmax = jmax (N1, N2);
143
144 auto N = N1 + N2 - 1;
145
146 for (int i = 0; i < N; ++i)
147 {
148 FloatingType value (0);
149
150 for (int j = 0; j < Nmax; ++j)
151 if (j >= 0 && j < N1 && i - j >= 0 && i - j < N2)
152 value = value + (*this)[j] * other[i - j];
153
154 result.coeffs.add (value);
155 }
156
157 return result;
158 }
159
160private:
161 //==============================================================================
163
165};
166
167} // namespace dsp
168} // namespace juce
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_Array.h:56
int size() const noexcept
Definition juce_Array.h:215
Polynomial(Values... items)
Definition juce_Polynomial.h:78
Polynomial()
Definition juce_Polynomial.h:42
Polynomial(const Polynomial &)=default
Polynomial< FloatingType > getSumWith(const Polynomial< FloatingType > &other) const
Definition juce_Polynomial.h:121
Polynomial< FloatingType > withGain(double gain) const
Definition juce_Polynomial.h:110
Array< FloatingType > coeffs
Definition juce_Polynomial.h:162
Polynomial(const FloatingType *coefficients, int numCoefficients)
Definition juce_Polynomial.h:55
Polynomial< FloatingType > getProductWith(const Polynomial< FloatingType > &other) const
Definition juce_Polynomial.h:135
Polynomial(Polynomial &&)=default
int getOrder() noexcept
Definition juce_Polynomial.h:103
register unsigned j
Definition inflate.c:1576
int y
Definition inflate.c:1588
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
static PuglViewHint int value
Definition pugl.h:1708
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define jassert(expression)
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
#define N
Definition nseel-cfunc.c:36
return c
Definition crypt.c:175
int result
Definition process.c:1455