LMMS
Loading...
Searching...
No Matches
juce_FastMathApproximations.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
37{
44 template <typename FloatType>
45 static FloatType cosh (FloatType x) noexcept
46 {
47 auto x2 = x * x;
48 auto numerator = -(39251520 + x2 * (18471600 + x2 * (1075032 + 14615 * x2)));
49 auto denominator = -39251520 + x2 * (1154160 + x2 * (-16632 + 127 * x2));
50 return numerator / denominator;
51 }
52
59 template <typename FloatType>
60 static void cosh (FloatType* values, size_t numValues) noexcept
61 {
62 for (size_t i = 0; i < numValues; ++i)
63 values[i] = FastMathApproximations::cosh (values[i]);
64 }
65
72 template <typename FloatType>
73 static FloatType sinh (FloatType x) noexcept
74 {
75 auto x2 = x * x;
76 auto numerator = -x * (11511339840 + x2 * (1640635920 + x2 * (52785432 + x2 * 479249)));
77 auto denominator = -11511339840 + x2 * (277920720 + x2 * (-3177720 + x2 * 18361));
78 return numerator / denominator;
79 }
80
87 template <typename FloatType>
88 static void sinh (FloatType* values, size_t numValues) noexcept
89 {
90 for (size_t i = 0; i < numValues; ++i)
91 values[i] = FastMathApproximations::sinh (values[i]);
92 }
93
100 template <typename FloatType>
101 static FloatType tanh (FloatType x) noexcept
102 {
103 auto x2 = x * x;
104 auto numerator = x * (135135 + x2 * (17325 + x2 * (378 + x2)));
105 auto denominator = 135135 + x2 * (62370 + x2 * (3150 + 28 * x2));
106 return numerator / denominator;
107 }
108
115 template <typename FloatType>
116 static void tanh (FloatType* values, size_t numValues) noexcept
117 {
118 for (size_t i = 0; i < numValues; ++i)
119 values[i] = FastMathApproximations::tanh (values[i]);
120 }
121
122 //==============================================================================
129 template <typename FloatType>
130 static FloatType cos (FloatType x) noexcept
131 {
132 auto x2 = x * x;
133 auto numerator = -(-39251520 + x2 * (18471600 + x2 * (-1075032 + 14615 * x2)));
134 auto denominator = 39251520 + x2 * (1154160 + x2 * (16632 + x2 * 127));
135 return numerator / denominator;
136 }
137
144 template <typename FloatType>
145 static void cos (FloatType* values, size_t numValues) noexcept
146 {
147 for (size_t i = 0; i < numValues; ++i)
148 values[i] = FastMathApproximations::cos (values[i]);
149 }
150
157 template <typename FloatType>
158 static FloatType sin (FloatType x) noexcept
159 {
160 auto x2 = x * x;
161 auto numerator = -x * (-11511339840 + x2 * (1640635920 + x2 * (-52785432 + x2 * 479249)));
162 auto denominator = 11511339840 + x2 * (277920720 + x2 * (3177720 + x2 * 18361));
163 return numerator / denominator;
164 }
165
172 template <typename FloatType>
173 static void sin (FloatType* values, size_t numValues) noexcept
174 {
175 for (size_t i = 0; i < numValues; ++i)
176 values[i] = FastMathApproximations::sin (values[i]);
177 }
178
185 template <typename FloatType>
186 static FloatType tan (FloatType x) noexcept
187 {
188 auto x2 = x * x;
189 auto numerator = x * (-135135 + x2 * (17325 + x2 * (-378 + x2)));
190 auto denominator = -135135 + x2 * (62370 + x2 * (-3150 + 28 * x2));
191 return numerator / denominator;
192 }
193
200 template <typename FloatType>
201 static void tan (FloatType* values, size_t numValues) noexcept
202 {
203 for (size_t i = 0; i < numValues; ++i)
204 values[i] = FastMathApproximations::tan (values[i]);
205 }
206
207 //==============================================================================
214 template <typename FloatType>
215 static FloatType exp (FloatType x) noexcept
216 {
217 auto numerator = 1680 + x * (840 + x * (180 + x * (20 + x)));
218 auto denominator = 1680 + x *(-840 + x * (180 + x * (-20 + x)));
219 return numerator / denominator;
220 }
221
228 template <typename FloatType>
229 static void exp (FloatType* values, size_t numValues) noexcept
230 {
231 for (size_t i = 0; i < numValues; ++i)
232 values[i] = FastMathApproximations::exp (values[i]);
233 }
234
241 template <typename FloatType>
242 static FloatType logNPlusOne (FloatType x) noexcept
243 {
244 auto numerator = x * (7560 + x * (15120 + x * (9870 + x * (2310 + x * 137))));
245 auto denominator = 7560 + x * (18900 + x * (16800 + x * (6300 + x * (900 + 30 * x))));
246 return numerator / denominator;
247 }
248
255 template <typename FloatType>
256 static void logNPlusOne (FloatType* values, size_t numValues) noexcept
257 {
258 for (size_t i = 0; i < numValues; ++i)
259 values[i] = FastMathApproximations::logNPlusOne (values[i]);
260 }
261};
262
263} // namespace dsp
264} // namespace juce
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_FastMathApproximations.h:37
static void cos(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:145
static FloatType tanh(FloatType x) noexcept
Definition juce_FastMathApproximations.h:101
static void tanh(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:116
static FloatType sinh(FloatType x) noexcept
Definition juce_FastMathApproximations.h:73
static FloatType sin(FloatType x) noexcept
Definition juce_FastMathApproximations.h:158
static FloatType logNPlusOne(FloatType x) noexcept
Definition juce_FastMathApproximations.h:242
static void sin(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:173
static FloatType exp(FloatType x) noexcept
Definition juce_FastMathApproximations.h:215
static void logNPlusOne(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:256
static FloatType cos(FloatType x) noexcept
Definition juce_FastMathApproximations.h:130
static FloatType tan(FloatType x) noexcept
Definition juce_FastMathApproximations.h:186
static void cosh(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:60
static void sinh(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:88
static void exp(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:229
static FloatType cosh(FloatType x) noexcept
Definition juce_FastMathApproximations.h:45
static void tan(FloatType *values, size_t numValues) noexcept
Definition juce_FastMathApproximations.h:201