#ifndef ATOOLS_Math_MathTools_H #define ATOOLS_Math_MathTools_H /* Declarations for discrete functions */ #ifdef __GNUC__ // GNU C++ Compiler #include #include /* if __GNUC__ == 3 && __GNUC_MINOR__ == 0. if defined __GNUC__ && defined __cplusplus && __GNUC_MINOR__ >= 8 if !defined __GNUC__ || __GNUC__ < 2 || __GNUC_MINOR__ < 7 #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) ... Test for GCC > 3.2.0 #if GCC_VERSION > 30200 */ #endif #if defined(__sgi) && !defined(__GNUC__) // SGI IRIX C++ Compiler, complex but not double methods need "std::", e.g. Abs() exp() #include #include #endif #include "ATOOLS/Math/MyComplex.H" namespace ATOOLS { template const Type &Min(const Type &a,const Type &b) { return a const Type &Max(const Type &a,const Type &b) { return a>b?a:b; } template Type &Min(Type &a,Type &b) { return a Type &Max(Type &a,Type &b) { return a>b?a:b; } inline double Accu() {return 1.e-12;} inline double SqrtAccu() {return 1.e-6;} inline int Sign(const int& a) { return a<0?-1:1; } inline double Sign(const double& a) { return a<0.0?-1.0:1.0; } inline double Theta(const double &a) { return a<0.0?0.0:1.0; } inline int iabs(const int& a) { return a<0?-a:a; } inline double dabs(const double& a) { return a<0.0?-a:a; } template inline Scalar sqr(const Scalar &x) { return x*x; } template inline std::complex csqr(const std::complex &x) { return x*x; } inline int IsZero(const double &a,const double &crit) { return dabs(a) inline bool IsNan(const Scalar& x); template inline bool IsBad(const Scalar& x); template inline bool IsZero(const Scalar& x); template inline Scalar Abs(const Scalar& x); template inline Scalar Abs(const std::complex& x); template<> inline bool IsNan(const double& x) { return std::isnan(x)||std::isnan(-x); } template<> inline bool IsBad(const double& x) { return IsNan(x)||std::isinf(x)||std::isinf(-x); } template<> inline bool IsZero(const double& x) { return dabs(x) inline double Abs(const double& x) { return x>0.0?x:-x; } template<> inline bool IsNan(const long double& x) { return std::isnan(x)||std::isnan(-x); } template<> inline bool IsBad(const long double& x) { return IsNan(x)||std::isinf(x)||std::isinf(-x); } template<> inline bool IsZero(const long double& x) { return dabs(x) inline long double Abs(const long double& x) { return x>0.0?x:-x; } template<> inline bool IsNan(const Complex& x) { return (std::isnan(real(x)) || std::isnan(imag(x)) || std::isnan(-real(x)) || std::isnan(-imag(x))); } template<> inline bool IsBad(const Complex& x) { return IsNan(x)||std::isinf(real(x))||std::isinf(imag(x)) ||std::isinf(-real(x))||std::isinf(-imag(x)); } template<> inline bool IsZero(const Complex& x) { return std::abs(x) inline double Abs(const Complex& x) { return std::abs(x); } template<> inline bool IsNan > (const std::complex& x) { return (std::isnan(real(x)) || std::isnan(imag(x)) || std::isnan(-real(x)) || std::isnan(-imag(x))); } template<> inline bool IsBad > (const std::complex& x) { return IsNan(x)||std::isinf(real(x))||std::isinf(imag(x)) ||std::isinf(-real(x))||std::isinf(-imag(x)); } template<> inline bool IsZero > (const std::complex& x) { return std::abs(x) inline long double Abs (const std::complex& x) { return std::abs(x); } template struct promote_trait { }; #define DECLARE_PROMOTE(A,B,C) \ template<> struct promote_trait { \ typedef C T_promote; \ } DECLARE_PROMOTE(double,Complex,Complex); DECLARE_PROMOTE(Complex,double,Complex); DECLARE_PROMOTE(int,double,double); DECLARE_PROMOTE(double,int,double); DECLARE_PROMOTE(int,Complex,Complex); DECLARE_PROMOTE(Complex,int,Complex); DECLARE_PROMOTE(double,double,double); DECLARE_PROMOTE(Complex,Complex,Complex); DECLARE_PROMOTE(long double,std::complex, std::complex); DECLARE_PROMOTE(std::complex,long double, std::complex); DECLARE_PROMOTE(int,long double,long double); DECLARE_PROMOTE(long double,int,long double); DECLARE_PROMOTE(int,std::complex,std::complex); DECLARE_PROMOTE(std::complex,int,std::complex); DECLARE_PROMOTE(long double,long double,long double); DECLARE_PROMOTE(std::complex,std::complex, std::complex); #define PROMOTE(TYPE1,TYPE2) typename promote_trait::T_promote /*! \file \brief contains a collection of simple mathematical functions */ /*! \fn inline Type Min(Type a, Type b) \brief returns the minimum of two numbers */ /*! \fn inline Type Max(Type a, Type b) \brief returns the maximum of two numbers */ /*! \fn inline int Sign(const int& a) {return (a<0) ? -1 : 1;} \brief returns the sign of the argument */ /*! \fn inline int iabs(const int& a) {return a>0 ? a : -a;} \brief returns the absolute value of the argument */ /*! \fn inline double dabs(const double& a) {return a>0 ? a : -a;} \brief returns the absolute value of the argument */ /*! \fn inline double sqr(double x) {return x*x;} \brief returns the argument squared */ /*! \fn inline double Accu() {return 1.e-12;}; \brief returns a (platform dependent) precission, default is \f$1^{-12}\f$ */ /*! \fn inline int IsZero(const double a) \brief returns \em true if argument is smaller than Accu() */ /*! \fn inline int IsZero(const Complex& a) \brief returns \em true if argument is smaller than Accu() */ /*! \fn inline int IsEqual(const double a,const double b) \brief returns \em true if arguments are equal (compared to Accu()) */ /*! \fn inline int IsEqual(const Complex& a,const Complex& b) \brief returns \em true if arguments are equal (compared to Accu()) */ /*! \fn inline Complex csqrt(const double d) \brief returns the complex root of a (possibly negative) float or double variable */ /*! \fn inline Complex csqr(Complex x) \brief returns the argument squared */ /*! \fn double Gammln(double xx) \brief calculates the logarithm of the Gammafunction */ /*! \fn double ReIncomplietGamma0(double xx) \brief calculates the real part of the incomplete Gammafunction. */ /*! \fn double DiLog(double x) \brief calculates the real part of Li_2(x). */ } #endif