OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_FastMathApproximations.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27 namespace juce
28{
29 namespace dsp
30{
31
37 struct FastMathApproximations
38{
45 template <typename FloatType>
46 static FloatType cosh (FloatType x) noexcept
47 {
48 auto x2 = x * x;
49 auto numerator = -(39251520 + x2 * (18471600 + x2 * (1075032 + 14615 * x2)));
50 auto denominator = -39251520 + x2 * (1154160 + x2 * (-16632 + 127 * x2));
51 return numerator / denominator;
52 }
53
60 template <typename FloatType>
61 static void cosh (FloatType* values, size_t numValues) noexcept
62 {
63 for (size_t i = 0; i < numValues; ++i)
64 values[i] = FastMathApproximations::cosh (values[i]);
65 }
66
73 template <typename FloatType>
74 static FloatType sinh (FloatType x) noexcept
75 {
76 auto x2 = x * x;
77 auto numerator = -x * (11511339840 + x2 * (1640635920 + x2 * (52785432 + x2 * 479249)));
78 auto denominator = -11511339840 + x2 * (277920720 + x2 * (-3177720 + x2 * 18361));
79 return numerator / denominator;
80 }
81
88 template <typename FloatType>
89 static void sinh (FloatType* values, size_t numValues) noexcept
90 {
91 for (size_t i = 0; i < numValues; ++i)
92 values[i] = FastMathApproximations::sinh (values[i]);
93 }
94
101 template <typename FloatType>
102 static FloatType tanh (FloatType x) noexcept
103 {
104 auto x2 = x * x;
105 auto numerator = x * (135135 + x2 * (17325 + x2 * (378 + x2)));
106 auto denominator = 135135 + x2 * (62370 + x2 * (3150 + 28 * x2));
107 return numerator / denominator;
108 }
109
116 template <typename FloatType>
117 static void tanh (FloatType* values, size_t numValues) noexcept
118 {
119 for (size_t i = 0; i < numValues; ++i)
120 values[i] = FastMathApproximations::tanh (values[i]);
121 }
122
123 //==============================================================================
130 template <typename FloatType>
131 static FloatType cos (FloatType x) noexcept
132 {
133 auto x2 = x * x;
134 auto numerator = -(-39251520 + x2 * (18471600 + x2 * (-1075032 + 14615 * x2)));
135 auto denominator = 39251520 + x2 * (1154160 + x2 * (16632 + x2 * 127));
136 return numerator / denominator;
137 }
138
145 template <typename FloatType>
146 static void cos (FloatType* values, size_t numValues) noexcept
147 {
148 for (size_t i = 0; i < numValues; ++i)
149 values[i] = FastMathApproximations::cos (values[i]);
150 }
151
158 template <typename FloatType>
159 static FloatType sin (FloatType x) noexcept
160 {
161 auto x2 = x * x;
162 auto numerator = -x * (-11511339840 + x2 * (1640635920 + x2 * (-52785432 + x2 * 479249)));
163 auto denominator = 11511339840 + x2 * (277920720 + x2 * (3177720 + x2 * 18361));
164 return numerator / denominator;
165 }
166
173 template <typename FloatType>
174 static void sin (FloatType* values, size_t numValues) noexcept
175 {
176 for (size_t i = 0; i < numValues; ++i)
177 values[i] = FastMathApproximations::sin (values[i]);
178 }
179
186 template <typename FloatType>
187 static FloatType tan (FloatType x) noexcept
188 {
189 auto x2 = x * x;
190 auto numerator = x * (-135135 + x2 * (17325 + x2 * (-378 + x2)));
191 auto denominator = -135135 + x2 * (62370 + x2 * (-3150 + 28 * x2));
192 return numerator / denominator;
193 }
194
201 template <typename FloatType>
202 static void tan (FloatType* values, size_t numValues) noexcept
203 {
204 for (size_t i = 0; i < numValues; ++i)
205 values[i] = FastMathApproximations::tan (values[i]);
206 }
207
208 //==============================================================================
215 template <typename FloatType>
216 static FloatType exp (FloatType x) noexcept
217 {
218 auto numerator = 1680 + x * (840 + x * (180 + x * (20 + x)));
219 auto denominator = 1680 + x *(-840 + x * (180 + x * (-20 + x)));
220 return numerator / denominator;
221 }
222
229 template <typename FloatType>
230 static void exp (FloatType* values, size_t numValues) noexcept
231 {
232 for (size_t i = 0; i < numValues; ++i)
233 values[i] = FastMathApproximations::exp (values[i]);
234 }
235
242 template <typename FloatType>
243 static FloatType logNPlusOne (FloatType x) noexcept
244 {
245 auto numerator = x * (7560 + x * (15120 + x * (9870 + x * (2310 + x * 137))));
246 auto denominator = 7560 + x * (18900 + x * (16800 + x * (6300 + x * (900 + 30 * x))));
247 return numerator / denominator;
248 }
249
256 template <typename FloatType>
257 static void logNPlusOne (FloatType* values, size_t numValues) noexcept
258 {
259 for (size_t i = 0; i < numValues; ++i)
260 values[i] = FastMathApproximations::logNPlusOne (values[i]);
261 }
262};
263
264} // namespace dsp
265} // namespace juce
juce::dsp::FastMathApproximations
Definition: juce_FastMathApproximations.h:38
juce::dsp::FastMathApproximations::cos
static void cos(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:146
juce::dsp::FastMathApproximations::tanh
static FloatType tanh(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:102
juce::dsp::FastMathApproximations::tanh
static void tanh(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:117
juce::dsp::FastMathApproximations::sinh
static FloatType sinh(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:74
juce::dsp::FastMathApproximations::sin
static FloatType sin(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:159
juce::dsp::FastMathApproximations::logNPlusOne
static FloatType logNPlusOne(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:243
juce::dsp::FastMathApproximations::sin
static void sin(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:174
juce::dsp::FastMathApproximations::exp
static FloatType exp(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:216
juce::dsp::FastMathApproximations::logNPlusOne
static void logNPlusOne(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:257
juce::dsp::FastMathApproximations::cos
static FloatType cos(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:131
juce::dsp::FastMathApproximations::tan
static FloatType tan(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:187
juce::dsp::FastMathApproximations::cosh
static void cosh(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:61
juce::dsp::FastMathApproximations::sinh
static void sinh(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:89
juce::dsp::FastMathApproximations::exp
static void exp(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:230
juce::dsp::FastMathApproximations::cosh
static FloatType cosh(FloatType x) noexcept
Definition: juce_FastMathApproximations.h:46
juce::dsp::FastMathApproximations::tan
static void tan(FloatType *values, size_t numValues) noexcept
Definition: juce_FastMathApproximations.h:202