1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2 * Copyright (C) 2011-2021 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef MT32EMU_MMATH_H
19 #define MT32EMU_MMATH_H
20
21 #include <cmath>
22
23 namespace MT32Emu {
24
25 // Mathematical constants
26 const double DOUBLE_PI = 3.141592653589793;
27 const double DOUBLE_LN_10 = 2.302585092994046;
28 const float FLOAT_PI = 3.1415927f;
29 const float FLOAT_2PI = 6.2831853f;
30 const float FLOAT_LN_2 = 0.6931472f;
31 const float FLOAT_LN_10 = 2.3025851f;
32
POWF(float x,float y)33 static inline float POWF(float x, float y) {
34 return pow(x, y);
35 }
36
EXPF(float x)37 static inline float EXPF(float x) {
38 return exp(x);
39 }
40
EXP2F(float x)41 static inline float EXP2F(float x) {
42 #ifdef __APPLE__
43 // on OSX exp2f() is 1.59 times faster than "exp() and the multiplication with FLOAT_LN_2"
44 return exp2f(x);
45 #else
46 return exp(FLOAT_LN_2 * x);
47 #endif
48 }
49
EXP10F(float x)50 static inline float EXP10F(float x) {
51 return exp(FLOAT_LN_10 * x);
52 }
53
LOGF(float x)54 static inline float LOGF(float x) {
55 return log(x);
56 }
57
LOG2F(float x)58 static inline float LOG2F(float x) {
59 return log(x) / FLOAT_LN_2;
60 }
61
LOG10F(float x)62 static inline float LOG10F(float x) {
63 return log10(x);
64 }
65
66 } // namespace MT32Emu
67
68 #endif // #ifndef MT32EMU_MMATH_H
69