//+------------------------------------------------------------------+ //| complex.mqh | //| Copyright 2003-2012 Sergey Bochkanov (ALGLIB project) | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ //| Implementation of ALGLIB library in MetaQuotes Language 5 | //| | //| The features of the library include: | //| - Linear algebra (direct algorithms, EVD, SVD) | //| - Solving systems of linear and non-linear equations | //| - Interpolation | //| - Optimization | //| - FFT (Fast Fourier Transform) | //| - Numerical integration | //| - Linear and nonlinear least-squares fitting | //| - Ordinary differential equations | //| - Computation of special functions | //| - Descriptive statistics and hypothesis testing | //| - Data analysis - classification, regression | //| - Implementing linear algebra algorithms, interpolation, etc. | //| in high-precision arithmetic (using MPFR) | //| | //| This file is free software; you can redistribute it and/or | //| modify it under the terms of the GNU General Public License as | //| published by the Free Software Foundation (www.fsf.org); either | //| version 2 of the License, or (at your option) any later version. | //| | //| This program is distributed in the hope that it will be useful, | //| but WITHOUT ANY WARRANTY; without even the implied warranty of | //| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | //| GNU General Public License for more details. | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Complex numbers | //+------------------------------------------------------------------+ struct al_complex { public: double re; // real part double im; // imaginary part public: al_complex(void); al_complex(const double x); al_complex(const double x,const double y); ~al_complex(void); //--- operations void Copy(const al_complex &rhs); bool Eq(const al_complex &lhs,const al_complex &rhs); bool NotEq(const al_complex &lhs,const al_complex &rhs); al_complex Add(const al_complex &lhs,const al_complex &rhs); al_complex Sub(const al_complex &lhs,const al_complex &rhs); al_complex Mul(const al_complex &lhs,const al_complex &rhs); al_complex Div(const al_complex &lhs,const al_complex &rhs); al_complex Conjugate(void); //--- overloading void operator=(const double rhs); void operator=(const al_complex &rhs); void operator+=(const al_complex &rhs); void operator-=(const al_complex &rhs); bool operator==(const al_complex &rhs); bool operator==(const double rhs); bool operator!=(const al_complex &rhs); bool operator!=(const double rhs); al_complex operator+(const al_complex &rhs); al_complex operator+(const double rhs); al_complex operator+(void); al_complex operator-(const al_complex &rhs); al_complex operator-(const double rhs); al_complex operator-(void); al_complex operator*(const al_complex &rhs); al_complex operator*(const double rhs); al_complex operator/(const al_complex &rhs); al_complex operator/(const double rhs); }; //+------------------------------------------------------------------+ //| Constructor without parameters | //+------------------------------------------------------------------+ al_complex::al_complex(void): re(0),im(0) { } //+------------------------------------------------------------------+ //| Constructor with one parameter | //+------------------------------------------------------------------+ al_complex::al_complex(const double x): re(x),im(0) { } //+------------------------------------------------------------------+ //| Constructor with two parameters | //+------------------------------------------------------------------+ al_complex::al_complex(const double x,const double y): re(x),im(y) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ al_complex::~al_complex(void) { } //+------------------------------------------------------------------+ //| Copy complex | //+------------------------------------------------------------------+ void al_complex::Copy(const al_complex &rhs) { re=rhs.re; im=rhs.im; } //+------------------------------------------------------------------+ //| Comparison (==) | //+------------------------------------------------------------------+ bool al_complex::Eq(const al_complex &lhs,const al_complex &rhs) { //--- comparison if(lhs.re==rhs.re && lhs.im==rhs.im) return(true); //--- numbers are not equal return(false); } //+------------------------------------------------------------------+ //| Comparison (!=) | //+------------------------------------------------------------------+ bool al_complex::NotEq(const al_complex &lhs,const al_complex &rhs) { //--- comparison if(lhs.re!=rhs.re || lhs.im!=rhs.im) return(true); //--- numbers are equal return(false); } //+------------------------------------------------------------------+ //| Sum | //+------------------------------------------------------------------+ al_complex al_complex::Add(const al_complex &lhs,const al_complex &rhs) { al_complex res; //--- sum res.re=lhs.re+rhs.re; res.im=lhs.im+rhs.im; //--- return result return(res); } //+------------------------------------------------------------------+ //| Subtraction | //+------------------------------------------------------------------+ al_complex al_complex::Sub(const al_complex &lhs,const al_complex &rhs) { al_complex res; //--- subtraction res.re=lhs.re-rhs.re; res.im=lhs.im-rhs.im; //--- return result return(res); } //+------------------------------------------------------------------+ //| Multiplication | //+------------------------------------------------------------------+ al_complex al_complex::Mul(const al_complex &lhs,const al_complex &rhs) { al_complex res; //--- multiplication res.re=lhs.re*rhs.re-lhs.im*rhs.im; res.im=lhs.re*rhs.im+lhs.im*rhs.re; //--- return result return(res); } //+------------------------------------------------------------------+ //| Division | //+------------------------------------------------------------------+ al_complex al_complex::Div(const al_complex &lhs,const al_complex &rhs) { //--- empty complex value al_complex res(EMPTY_VALUE,EMPTY_VALUE); //--- check if(rhs.re==0 && rhs.im==0) { Print(__FUNCTION__+": number is zero"); return(res); } //--- create variables double e; double f; //--- division if(MathAbs(rhs.im)