20 #define MATH_DEBUG // switch on error checks
21 #define NO_TEMPLATE_INLINE // switch off inlines in template classes
33 const double Pi = 3.1415926535897932384626433832795;
34 const double Pi2 = Pi*2.0;
35 const double Pi05 = Pi*0.5;
36 const double Rad = Pi/180.0;
37 const double Deg = 180.0/Pi;
41 typedef unsigned char BYTE;
60 inline T sqr (
const T a) {
return (a == 0.0 ? (T)0 : a*a); }
62 inline double sign (
const double a,
const double b)
63 {
return (b >= 0 ? fabs(a) : -fabs(a)); }
66 inline double norm (
double f)
69 inline double norm2 (
double f)
72 inline int norm (
int i)
75 inline bool pow (
bool base,
bool e)
78 inline int pow (
int base,
int e)
79 {
return (
int)pow ((
double)base, (
double)e); }
84 inline float conj(
float a)
87 inline double conj(
double a)
90 inline bool iszero (
double d)
93 inline bool iszero (std::complex<double> d)
95 return d.real() == 0 && d.imag() == 0;
98 inline bool operator> (
const std::complex<double> &z1,
99 const std::complex<double> &z2)
101 return std::norm(z1) > std::norm(z2);
104 inline bool operator< (const std::complex<double> &z1,
105 const std::complex<double> &z2)
107 return std::norm(z1) < std::norm(z2);
110 inline bool operator! (
const std::complex<double> &z)
112 return z.real() == 0 && z.imag() == 0;
115 inline std::complex<double> hadamard (
const std::complex<double>& a,
116 const std::complex<double>& b)
118 return std::complex<double> (a.real()*b.real(), a.imag()*b.imag());
121 inline int binomial_coeff (
int n,
int r)
124 for (i = n; i > std::max (r, (n-r)); i--) sum *= i;
125 for (i = std::min (r, (n-r)); i > 1; i--) sum /= i;
129 inline double rad (
double deg) {
return deg*Rad; }
130 inline double deg (
double rad) {
return rad*Deg; }
132 #ifdef __BORLANDC__ // BorlandC doesn't know about atanh
133 inline double atanh (
double x)
134 {
return 0.5 * log ((1.0+x) / (1.0-x)); }