Index: mttroot/mtt/cc/include/useful-functions.hh ================================================================== --- mttroot/mtt/cc/include/useful-functions.hh +++ mttroot/mtt/cc/include/useful-functions.hh @@ -1,19 +1,39 @@ #ifndef HAVE_USEFUL_FUNCTIONS_HH #define HAVE_USEFUL_FUNCTIONS_HH -template -inline T max (const T &x1, const T &x2) + +#ifdef __CPLUSPLUS +template +#else +#define inline // strip from pre-processed file +#define class_t double +#endif // __CPLUSPLUS + + +// == Template functions == + +inline class_t +max (const class_t &x1, const class_t &x2) +{ + return ((x1 >= x2) ? x1 : (x1 < x2) ? x2 : 0); +} + +inline class_t +min (const class_t &x1, const class_t &x2) +{ + return ((x1 <= x2) ? x1 : (x1 > x2) ? x2 : 0); +} + +inline class_t +sign (const class_t &x) { - return (x1 >= x2) ? x1 : (x2 < x1) ? x2 : 0; + return ((x > 0) ? +1 : (x < 0) ? -1 : 0); } -template -inline T min (const T &x1, const T &x2) -{ - return (x1 <= x2) ? x1 : (x2 > x1) ? x2 : 0; -} + +// == Octave functions == inline Matrix ones (const int r = 1, const int c = 1) { Matrix m (r, c, 1.0); @@ -53,16 +73,6 @@ { Matrix m (r, c, 0.0); return m; } -template -inline int -sign (T x) -{ - return - (0 < x) ? +1 : - (0 > x) ? -1 : - 0; -} - #endif // HAVE_USEFUL_FUNCTIONS_HH