WE Core
Loading...
Searching...
No Matches
CoreMath.h
Go to the documentation of this file.
1/*
2 * File: CoreMath.h
3 *
4 * Created: 18/03/2017
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef CoreMath_h
23#define CoreMath_h
24
25#include <cmath>
26#include <limits>
27
35 constexpr long double LONG_PI {3.14159265358979323846264338327950288};
36 constexpr double DOUBLE_PI {static_cast<double>(LONG_PI)};
37
38 constexpr long double LONG_TAU {2 * LONG_PI};
39 constexpr double DOUBLE_TAU {static_cast<double>(LONG_TAU)};
40
41 constexpr long double LONG_E {2.71828182845904523536028747135266250};
42 constexpr double DOUBLE_E {static_cast<double>(LONG_E)};
43
44 template <typename T>
45 bool compareFloatsEqual(T x, T y, T tolerance = std::numeric_limits<T>::epsilon()) {
46 return std::abs(x - y) < tolerance;
47 }
48
49 constexpr double MINUS_INF_DB {-200};
50 inline double linearTodB(double val) { return val > 0 ? std::fmax(20 * std::log10(val), MINUS_INF_DB) : MINUS_INF_DB; }
51 inline double dBToLinear(double val) { return std::pow(10.0, val / 20.0); }
52}
53
54#endif /* CoreMath_h */
double linearTodB(double val)
Definition CoreMath.h:50
constexpr double DOUBLE_PI
Definition CoreMath.h:36
constexpr double MINUS_INF_DB
Definition CoreMath.h:49
constexpr double DOUBLE_E
Definition CoreMath.h:42
bool compareFloatsEqual(T x, T y, T tolerance=std::numeric_limits< T >::epsilon())
Definition CoreMath.h:45
constexpr long double LONG_PI
Definition CoreMath.h:35
constexpr long double LONG_E
Definition CoreMath.h:41
double dBToLinear(double val)
Definition CoreMath.h:51
constexpr double DOUBLE_TAU
Definition CoreMath.h:39
constexpr long double LONG_TAU
Definition CoreMath.h:38