diff options
Diffstat (limited to 'methods/linmin/bas_util.hpp')
-rw-r--r-- | methods/linmin/bas_util.hpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/methods/linmin/bas_util.hpp b/methods/linmin/bas_util.hpp new file mode 100644 index 0000000..ccdce9e --- /dev/null +++ b/methods/linmin/bas_util.hpp @@ -0,0 +1,65 @@ +#ifndef BAS_UTIL +#define BAS_UTIL +#define OPT_HEADER +#include <core/opt_traits.hpp> +#include <algorithm> +namespace opt_utilities +{ + template <typename T> + T tabs(T x) + { + return T(x)<T(0)?T(-x):T(x); + } + + template <typename T> + T sqr(T x) + { + return x*x; + } + + + template <typename T> + void shft3(T&a,T& b,T& c,T d) + { + opt_eq(a,b); + opt_eq(b,c); + opt_eq(c,d); + } + + template <typename T> + void shft(T& a,T& b,T& c,T d) + { + opt_eq(a,b); + opt_eq(b,c); + opt_eq(c,d); + } + // template <typename T> + // void swap(T& ax,T& bx) + //{ + // swap(ax,bx); + // T temp; + //opt_eq(temp,ax); + //opt_eq(ax,bx); + //opt_eq(bx,temp); + //} + + template <typename T> + T sign(const T& a,const T& b) + { + return b>=0?T(a>=0?T(a):T(-a)):T(a>=0?T(-a):T(a)); + } + + template <typename T> + T max(T a,T b) + { + return b>a?T(b):T(a); + } + + template <typename T> + void mov3(T& a,T& b,T& c, T& d,T& e,T& f) + { + opt_eq(a,d);opt_eq(b,e);opt_eq(c,f); + } +} + +#endif |