2 Copyright (C) 2014 Waves Audio Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __MinMaxUtilities_h__
21 #define __MinMaxUtilities_h__
24 #include "MiscUtils/MinMaxUtilities.h"
27 #include "BasicTypes/WUDefines.h"
28 #include "BasicTypes/WUMathConsts.h"
29 #include "WavesPublicAPI/wstdint.h"
35 // New accelerated templates
36 #if defined ( __cplusplus ) && !defined (__WUMinMax)
37 #define __WUMinMax // Also defined in Nativepr.h
40 template<class T> inline T WUMin(const T &a, const T &b) {return (a < b) ? a : b;} // requires only < to be defined for T
41 template<class T> inline T WUMax(const T &a,const T &b) {return (a < b) ? b : a;} // requires only < to be defined for T
42 template<class T> inline T WUMinMax(const T &Smallest, const T &Biggest, const T &Val) // requires only < to be defined for T
44 return ((Val < Smallest) ? Smallest : ((Biggest < Val) ? Biggest : Val));
48 template<class T> inline T WUMin(T a,T b) {return (a < b) ? a : b;} // requires only < to be defined for T
49 template<class T> inline T WUMax(T a,T b) {return (a < b) ? b : a;} // requires only < to be defined for T
50 template<class T> inline T WUMinMax(T SMALLEST, T BIGGEST, T X) // requires only < to be defined for T
52 return ((X < SMALLEST) ? SMALLEST : ((BIGGEST < X) ? BIGGEST : X));
57 #ifdef PLATFORM_WINDOWS
61 #define __abs(x) abs(x)
62 #define __labs(x) labs(x)
63 #define __fabs(x) fabs(x)
69 #include <iostream> // why don't know makes it work need to check
73 #define __abs(x) std::abs(x)
74 #define __labs(x) std::labs(x)
75 #define __fabs(x) std::fabs(x)
79 #include <iostream> // why don't know makes it work need to check
81 #define __abs(x) std::abs(x)
82 #define __labs(x) std::labs(x)
83 #define __fabs(x) std::fabs(x)
87 // log2: on Windows there's no proper definition for log2, whereas on other platform there is.
89 #if defined(PLATFORM_WINDOWS)
90 #define WUlog2(x) (kdOneOverLog2 * log10((x)))
92 #define WUlog2(x) log2(x)
96 template <class T> inline T WUAbs(const T &xA)
98 return (xA > T(0))? xA: -xA;
101 template <> inline int WUAbs(const int &xA)
106 //template <> inline int32_t WUAbs(const int32_t &xA)// 64BitConversion
108 // return __labs(xA);
111 template <> inline float WUAbs(const float &xA)
113 return (float) __fabs(xA);
116 template <> inline double WUAbs(const double &xA)
123 int32_t DllExport WURand(intptr_t in_Seed);
124 int32_t DllExport WURand();
125 int32_t DllExport rand_gen_formula(int32_t rndSeed);
127 template <class T> inline bool WUIsEqualWithTolerance(const T &xA, const T &xB, const T &xTolerance)
129 return (WUAbs(xA - xB) < xTolerance) ? true : false;