1 #ifndef __MinMaxUtilities_h__
2 #define __MinMaxUtilities_h__
5 #include "MiscUtils/MinMaxUtilities.h"
8 #include "BasicTypes/WUDefines.h"
9 #include "BasicTypes/WUMathConsts.h"
10 #include "WavesPublicAPI/wstdint.h"
12 // New accelerated templates
13 #if defined ( __cplusplus ) && !defined (__WUMinMax)
14 #define __WUMinMax // Also defined in Nativepr.h
17 template<class T> inline T WUMin(const T &a, const T &b) {return (a < b) ? a : b;} // requires only < to be defined for T
18 template<class T> inline T WUMax(const T &a,const T &b) {return (a < b) ? b : a;} // requires only < to be defined for T
19 template<class T> inline T WUMinMax(const T &Smallest, const T &Biggest, const T &Val) // requires only < to be defined for T
21 return ((Val < Smallest) ? Smallest : ((Biggest < Val) ? Biggest : Val));
25 template<class T> inline T WUMin(T a,T b) {return (a < b) ? a : b;} // requires only < to be defined for T
26 template<class T> inline T WUMax(T a,T b) {return (a < b) ? b : a;} // requires only < to be defined for T
27 template<class T> inline T WUMinMax(T SMALLEST, T BIGGEST, T X) // requires only < to be defined for T
29 return ((X < SMALLEST) ? SMALLEST : ((BIGGEST < X) ? BIGGEST : X));
33 #ifdef PLATFORM_WINDOWS
35 #define __abs(x) abs(x)
36 #define __labs(x) labs(x)
37 #define __fabs(x) fabs(x)
40 #include <iostream> // why don't know makes it work need to check
44 #define __abs(x) std::abs(x)
45 #define __labs(x) std::labs(x)
46 #define __fabs(x) std::fabs(x)
50 #include <iostream> // why don't know makes it work need to check
52 #define __abs(x) std::abs(x)
53 #define __labs(x) std::labs(x)
54 #define __fabs(x) std::fabs(x)
58 // log2: on Windows there's no proper definition for log2, whereas on other platform there is.
60 #if defined(PLATFORM_WINDOWS)
61 #define WUlog2(x) (kdOneOverLog2 * log10((x)))
63 #define WUlog2(x) log2(x)
67 template <class T> inline T WUAbs(const T &xA)
69 return (xA > T(0))? xA: -xA;
72 template <> inline int WUAbs(const int &xA)
77 //template <> inline int32_t WUAbs(const int32_t &xA)// 64BitConversion
82 template <> inline float WUAbs(const float &xA)
84 return (float) __fabs(xA);
87 template <> inline double WUAbs(const double &xA)
94 int32_t DllExport WURand(intptr_t in_Seed);
95 int32_t DllExport WURand();
96 int32_t DllExport rand_gen_formula(int32_t rndSeed);
98 template <class T> inline bool WUIsEqualWithTolerance(const T &xA, const T &xB, const T &xTolerance)
100 return (WUAbs(xA - xB) < xTolerance) ? true : false;