// complex standard header #pragma once #ifndef _COMPLEX_MPFT_ #define _COMPLEX_MPFT_ #ifndef RC_INVOKED //#include #include #include #include /* dummy if not C99 library */ #include #include #pragma pack(push,_CRT_PACKING) #pragma warning(push,3) #pragma warning(disable: 4244) _C_STD_BEGIN #ifndef _C_COMPLEX_MPFT_T #define _C_COMPLEX_MPFT_T typedef struct _C_mpft_complex { /* mpft complex */ mpfr::mpreal _Val[2]; } _C_mpft_complex; #endif /* _C_COMPLEX_MPFT_T */ _C_STD_END _STD_BEGIN typedef _CSTD _C_mpft_complex _Mcomplex_value; template<> class complex; // CLASS _Ctraits template<> class _Ctraits { // complex traits for mpfr::mpreal public: typedef mpfr::mpreal _Ty; static _Ty _Cosh(_Ty _Left, _Ty _Right) { // return cosh(_Left) * _Right return (_CSTD mpfr::cosh(_Left) * _Right); } static short _Exp(_Ty *_Pleft, _Ty _Right, short _Exponent) { // compute exp(*_Pleft) * _Right * 2 ^ _Exponent //_Left * 2 ^ _Exponent return ((short)(mpfr::exp(*_Pleft) * mpfr::ldexp(_Right, _Exponent)).toDouble()); } static _Ty _Infv(_Ty) { // return infinity return (_CSTD _Inf._Double); } static bool _Isinf(_Ty _Left) { // test for infinity return (_CSTD mpfr::isfinite(_Left)); } static bool _Isnan(_Ty _Left) { // test for NaN return (_CSTD mpfr::isnan(_Left)); } static _Ty _Nanv(_Ty) { // return NaN return (_CSTD _Nan._Double); } static _Ty _Sinh(_Ty _Left, _Ty _Right) { // return sinh(_Left) * _Right return (_CSTD mpfr::sinh(_Left) * _Right); } static _Ty atan2(_Ty _Yval, _Ty _Xval) { // return atan(_Yval / _Xval) return (_CSTD mpfr::atan2(_Yval, _Xval)); } static _Ty cos(_Ty _Left) { // return cos(_Left) return (_CSTD mpfr::cos(_Left)); } static _Ty exp(_Ty _Left) { // return exp(_Left) return (_CSTD mpfr::exp(_Left)); } static _Ty ldexp(_Ty _Left, int _Exponent) { // return _Left * 2 ^ _Exponent return (_CSTD mpfr::ldexp(_Left, _Exponent)); } static _Ty log(_Ty _Left) { // return log(_Left) return (_CSTD mpfr::log(_Left)); } static _Ty pow(_Ty _Left, _Ty _Right) { // return _Left ^ _Right return (_CSTD mpfr::pow(_Left, _Right)); } static _Ty sin(_Ty _Left) { // return sin(_Left) return (_CSTD mpfr::sin(_Left)); } static _Ty sqrt(_Ty _Left) { // return sqrt(_Left) return (_CSTD mpfr::sqrt(_Left)); } static _Ty tan(_Ty _Left) { // return tan(_Left) return (_CSTD mpfr::tan(_Left)); } }; // CLASS complex template<> class complex : public _Complex_base { // complex with mpfr::mpreal components public: typedef mpfr::mpreal _Ty; typedef complex<_Ty> _Myt; complex( const complex&); // defined below operator _Ty() const { return _Val[_RE]; } complex(const double& _Realval) : _Complex_base(_Realval, 0) { // construct from double component } //complex(const double& _Realval = 0, const double& _Imagval = 0) // : _Complex_base(_Realval, _Imagval) // { // construct from mpfr::mpreal component // } //complex() // : _Complex_base(0, 0) // { // construct from mpfr::mpreal components // } complex(const _Ty& _Realval = 0, const _Ty& _Imagval = 0) : _Complex_base(_Realval, _Imagval) { // construct from mpfr::mpreal components } complex(const _Mcomplex_value& _Right) : _Complex_base(_Right._Val[_RE], _Right._Val[_IM]) { // construct from mpfr::mpreal complex value } complex<_Ty>& operator=(const _Ty& _Right) { // assign real _Val[_RE] = _Right; _Val[_IM] = 0; return (*this); } _Myt& operator+=(const _Ty& _Right) { // add real _Val[_RE] = _Val[_RE] + _Right; return (*this); } _Myt& operator-=(const _Ty& _Right) { // subtract real _Val[_RE] = _Val[_RE] - _Right; return (*this); } _Myt& operator*=(const _Ty& _Right) { // multiply by real _Val[_RE] = _Val[_RE] * _Right; _Val[_IM] = _Val[_IM] * _Right; return (*this); } _Myt& operator/=(const _Ty& _Right) { // divide by real _Val[_RE] = _Val[_RE] / _Right; _Val[_IM] = _Val[_IM] / _Right; return (*this); } _Myt& operator+=(const _Myt& _Right) { // add other complex this->_Add(_Right); return (*this); } _Myt& operator-=(const _Myt& _Right) { // subtract other complex this->_Sub(_Right); return (*this); } _Myt& operator*=(const _Myt& _Right) { // multiply by other complex this->_Mul(_Right); return (*this); } _Myt& operator/=(const _Myt& _Right) { // divide by other complex this->_Div(_Right); return (*this); } template inline _Myt& operator=(const complex<_Other>& _Right) { // assign another complex _Val[_RE] = (_Ty)_Right._Val[_RE]; _Val[_IM] = (_Ty)_Right._Val[_IM]; return (*this); } template inline _Myt& operator+=(const complex<_Other>& _Right) { // add other complex this->_Add(_Right); return (*this); } template inline _Myt& operator-=(const complex<_Other>& _Right) { // subtract other complex this->_Sub(_Right); return (*this); } template inline _Myt& operator*=(const complex<_Other>& _Right) { // multiply by other complex this->_Mul(_Right); return (*this); } template inline _Myt& operator/=(const complex<_Other>& _Right) { // divide by other complex this->_Div(_Right); return (*this); } }; // CONSTRUCTORS FOR complex SPECIALIZATIONS inline complex::complex( const complex& _Right) : _Complex_base( (_Ty)_Right.real(), (_Ty)_Right.imag()) { // construct complex from complex } _STD_END #pragma warning(pop) #pragma pack(pop) #endif /* RC_INVOKED */ #endif /* _COMPLEX_MPFT_ */