21 #ifndef GRT_TYPEDEFS_HEADER
22 #define GRT_TYPEDEFS_HEADER
24 #include "GRTVersionInfo.h"
36 #define GRT_BEGIN_NAMESPACE namespace GRT {
37 #define GRT_END_NAMESPACE }
43 typedef long double LongFloat;
47 #define PI 3.14159265358979323846264338327950288
51 #define TWO_PI 6.28318530718
55 #define SQRT_TWO_PI 2.506628274631
58 template<
class T>
inline T SQR(
const T &a) {
return a*a;}
59 template<
class T>
inline void SWAP(T &a,T &b) { T temp(a); a = b; b = temp; }
60 template<
class T>
inline T SIGN(
const T &a,
const T &b) {
return (b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a));}
62 template<
class T>
inline void grt_swap(T &a,T &b) { T temp(a); a = b; b = temp; }
67 static T min() {
return std::numeric_limits< T >::min(); }
68 static T max() {
return std::numeric_limits< T >::max(); }
71 inline Float grt_sqr(
const Float &x ){
return x*x; }
73 inline Float grt_sqrt(
const Float &x ){
return sqrt(x); }
75 inline Float grt_antilog(
const Float &x ){
return exp( x ); }
77 inline Float grt_exp(
const Float &x ){
return exp( x ); }
79 inline Float grt_log(
const Float &x ){
return log( x ); }
81 inline Float grt_sigmoid(
const Float &x ) {
return 1.0 / (1.0 + exp(-x)); }
84 T grt_scale(
const T &x,
const T &minSource,
const T &maxSource,
const T &minTarget,
const T &maxTarget,
const bool constrain =
false){
86 if( x <= minSource )
return minTarget;
87 if( x >= maxSource )
return maxTarget;
89 if( minSource == maxSource )
return minTarget;
90 return (((x-minSource)*(maxTarget-minTarget))/(maxSource-minSource))+minTarget;
94 std::string grt_to_str(
const T &value ){
101 T grt_from_str(
const std::string &str ){
102 std::stringstream s( str );
108 #define grt_min(a,b) (((a)<(b))?(a):(b))
109 #define grt_max(a,b) (((a)>(b))?(a):(b))
112 #define MIN(a,b) (((a)<(b))?(a):(b))
115 #define MAX(a,b) (((a)>(b))?(a):(b))
118 #define GRT_DEFAULT_NULL_CLASS_LABEL 0
119 #define GRT_SAFE_CHECKING true
122 #ifdef __GRT_WINDOWS_BUILD__
123 #define grt_isnan(x) (x != x)
124 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
128 static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
129 #define NAN (*(const float *) __nan)
133 #define INFINITY (DBL_MAX+DBL_MAX)
144 #ifdef __GRT_OSX_BUILD__
145 #define grt_isnan(x) (x != x)
146 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
148 typedef unsigned int UINT;
149 typedef signed int SINT;
150 typedef unsigned long ULONG;
154 #ifdef __GRT_LINUX_BUILD__
155 #define grt_isnan(x) (x != x)
156 #define grt_isinf(x) (!grt_isnan(x) && grt_isnan(x - x))
158 typedef unsigned int UINT;
159 typedef signed int SINT;
160 typedef unsigned long ULONG;
166 #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 5)
167 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated(message)))
169 #define GRT_DEPRECATED_MSG(message, func) func __attribute__ ((deprecated))
171 #define GRT_DEPRECATED(func) func __attribute__ ((deprecated))
172 #elif defined(_MSC_VER)
173 #define GRT_DEPRECATED_MSG(message, func) __declspec(deprecated(message)) func
174 #define GRT_DEPRECATED(func) __declspec(deprecated) func
176 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
177 #define GRT_DEPRECATED_MSG(message, func) func
178 #define GRT_DEPRECATED(func) func
184 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
189 #define grt_to_str(x) (#x)
195 #define grt_assert(x) \
198 fprintf(stderr, "Assertion failed: %s, %s(), %d at \'%s\'\n", __FILENAME__, __func__, __LINE__, grt_to_str(x) ); \
203 #define grt_assert(x)
224 #endif //GRT_TYPEDEFS_HEADER