21 #ifndef GRT_TYPEDEFS_HEADER
22 #define GRT_TYPEDEFS_HEADER
24 #include "GRTVersionInfo.h"
36 #ifdef __GRT_WINDOWS_BUILD__
45 #define GRT_BEGIN_NAMESPACE namespace GRT {
46 #define GRT_END_NAMESPACE }
52 typedef long double LongFloat;
56 #define PI 3.14159265358979323846264338327950288
60 #define TWO_PI 6.28318530718
64 #define SQRT_TWO_PI 2.506628274631
67 template<
class T>
inline T SQR(
const T &a) {
return a*a;}
68 template<
class T>
inline void SWAP(T &a,T &b) { T temp(a); a = b; b = temp; }
69 template<
class T>
inline T SIGN(
const T &a,
const T &b) {
return (b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a));}
71 template<
class T>
inline void grt_swap(T &a,T &b) { T temp(a); a = b; b = temp; }
76 static T min() {
return std::numeric_limits< T >::min(); }
77 static T max() {
return std::numeric_limits< T >::max(); }
80 inline Float grt_sqr(
const Float &x ){
return x*x; }
82 inline Float grt_sqrt(
const Float &x ){
return sqrt(x); }
84 inline Float grt_antilog(
const Float &x ){
return exp( x ); }
86 inline Float grt_exp(
const Float &x ){
return exp( x ); }
88 inline Float grt_log(
const Float &x ){
return log( x ); }
90 inline Float grt_sigmoid(
const Float &x ) {
return 1.0 / (1.0 + exp(-x)); }
93 T grt_scale(
const T &x,
const T &minSource,
const T &maxSource,
const T &minTarget,
const T &maxTarget,
const bool constrain =
false){
95 if( x <= minSource )
return minTarget;
96 if( x >= maxSource )
return maxTarget;
98 if( minSource == maxSource )
return minTarget;
99 return (((x-minSource)*(maxTarget-minTarget))/(maxSource-minSource))+minTarget;
103 std::string grt_to_str(
const T &value ){
110 T grt_from_str(
const std::string &str ){
111 std::stringstream s( str );
117 #define grt_min(a,b) (((a)<(b))?(a):(b))
118 #define grt_max(a,b) (((a)>(b))?(a):(b))
120 #define GRT_DEFAULT_NULL_CLASS_LABEL 0
121 #define GRT_SAFE_CHECKING true
128 #ifdef __GRT_WINDOWS_BUILD__
129 #define grt_isnan(x) (x != x)
130 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
134 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
135 #define NAN (*(const float *) __nan)
139 #define INFINITY (DBL_MAX+DBL_MAX)
148 #if !defined(GRT_STATIC_LIB) && defined(_MSC_VER)
150 #ifdef GRT_DLL_EXPORTS
151 #define GRT_API __declspec(dllexport)
152 #else // GRT_DLL_EXPORTS
153 #define GRT_API __declspec(dllimport)
154 #endif // GRT_DLL_EXPORTS
157 # pragma warning(disable: 4251)
158 #endif // !GRT_STATIC_LIB && MSC_VER
163 #ifdef __GRT_OSX_BUILD__
164 #define grt_isnan(x) (x != x)
165 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
167 typedef unsigned int UINT;
168 typedef signed int SINT;
169 typedef unsigned long ULONG;
173 #ifdef __GRT_LINUX_BUILD__
174 #define grt_isnan(x) (x != x)
175 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
177 typedef unsigned int UINT;
178 typedef signed int SINT;
179 typedef unsigned long ULONG;
185 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 5)
186 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated(message)))
188 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated))
190 #define GRT_DEPRECATED(func) func __attribute__ ((deprecated))
191 #elif defined(_MSC_VER)
192 #define GRT_DEPRECATED_MSG(message, func) __declspec(deprecated(message)) func
193 #define GRT_DEPRECATED(func) __declspec(deprecated) func
195 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
196 #define GRT_DEPRECATED_MSG(message, func) func
197 #define GRT_DEPRECATED(func) func
203 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
208 #define grt_to_str(x) (#x)
214 #if defined(_MSC_VER) && _MSC_VER <= 1800
216 #define grt_assert(x) \
219 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __FUNCTION__, __LINE__, grt_to_str(x) ); \
223 #else // _MSC_VER <= 1800
224 #define grt_assert(x) \
227 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __func__, __LINE__, grt_to_str(x) ); \
231 #endif // _MSC_VER <= 1800
233 #define grt_assert(x)
254 #endif //GRT_TYPEDEFS_HEADER