742 lines
23 KiB
Plaintext
742 lines
23 KiB
Plaintext
|
// xcomplex internal header
|
||
|
#pragma once
|
||
|
#ifndef _XCOMPLEX_
|
||
|
#define _XCOMPLEX_
|
||
|
|
||
|
// TEMPLATE FUNCTION imag
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl imag(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return imaginary component
|
||
|
return (_Left.imag());
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION real
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl real(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return real component
|
||
|
return (_Left.real());
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION _Fabs
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl _Fabs(const _CMPLX(_Ty)& _Left, int *_Pexp)
|
||
|
{ // return magnitude and scale factor
|
||
|
*_Pexp = 0;
|
||
|
_Ty _Av = real(_Left);
|
||
|
_Ty _Bv = imag(_Left);
|
||
|
|
||
|
if (_CTR(_Ty)::_Isinf(_Av) || _CTR(_Ty)::_Isinf(_Bv))
|
||
|
return (_CTR(_Ty)::_Infv(_Bv)); // at least one component is INF
|
||
|
else if (_CTR(_Ty)::_Isnan(_Av))
|
||
|
return (_Av); // real component is NaN
|
||
|
else if (_CTR(_Ty)::_Isnan(_Bv))
|
||
|
return (_Bv); // imaginary component is NaN
|
||
|
else
|
||
|
{ // neither component is NaN or INF
|
||
|
if (_Av < 0)
|
||
|
_Av = -_Av;
|
||
|
if (_Bv < 0)
|
||
|
_Bv = -_Bv;
|
||
|
if (_Av < _Bv)
|
||
|
{ // ensure that |_Bv| <= |_Av|
|
||
|
_Ty _Tmp = _Av;
|
||
|
_Av = _Bv;
|
||
|
_Bv = _Tmp;
|
||
|
}
|
||
|
|
||
|
if (_Av == 0)
|
||
|
return (_Av); // |0| == 0
|
||
|
if (1 <= _Av)
|
||
|
*_Pexp = 2, _Av = _Av * (_Ty)0.25, _Bv = _Bv * (_Ty)0.25;
|
||
|
else
|
||
|
*_Pexp = -2, _Av = _Av * 4, _Bv = _Bv * 4;
|
||
|
|
||
|
_Ty _Tmp = _Av - _Bv;
|
||
|
if (_Tmp == _Av)
|
||
|
return (_Av); // _Bv unimportant
|
||
|
else if (_Bv < _Tmp)
|
||
|
{ // use simple approximation
|
||
|
const _Ty _Qv = _Av / _Bv;
|
||
|
return (_Av + _Bv / (_Qv + _CTR(_Ty)::sqrt(_Qv * _Qv + 1)));
|
||
|
}
|
||
|
else
|
||
|
{ // use 1 1/2 precision to preserve bits
|
||
|
static const _Ty _Root2 =
|
||
|
(_Ty)1.4142135623730950488016887242096981L;
|
||
|
static const _Ty _Oneplusroot2high = (_Ty)2.4142L;
|
||
|
static const _Ty _Oneplusroot2low =
|
||
|
(_Ty)0.0000135623730950488016887242096980785697L;
|
||
|
|
||
|
const _Ty _Qv = _Tmp / _Bv;
|
||
|
const _Ty _Rv = (_Qv + 2) * _Qv;
|
||
|
const _Ty _Sv = _Rv / (_Root2 + _CTR(_Ty)::sqrt(_Rv + 2))
|
||
|
+ _Oneplusroot2low + _Qv + _Oneplusroot2high;
|
||
|
return (_Av + _Bv / _Sv);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator+
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator+(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // add complex to complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp += _Right);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator+(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // add real to complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
_Tmp.real(_Tmp.real() + _Right);
|
||
|
return (_Tmp);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator+(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // add complex to real
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp += _Right);
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator-
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator-(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // subtract complex from complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp -= _Right);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator-(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // subtract real from complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
_Tmp.real(_Tmp.real() - _Right);
|
||
|
return (_Tmp);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator-(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // subtract complex from real
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp -= _Right);
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator*
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator*(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // multiply complex by complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp *= _Right);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator*(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // multiply complex by real
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
_Tmp.real(_Tmp.real() * _Right);
|
||
|
_Tmp.imag(_Tmp.imag() * _Right);
|
||
|
return (_Tmp);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator*(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // multiply real by complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp *= _Right);
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator/
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator/(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // divide complex by complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp /= _Right);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator/(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // divide complex by real
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
_Tmp.real(_Tmp.real() / _Right);
|
||
|
_Tmp.imag(_Tmp.imag() / _Right);
|
||
|
return (_Tmp);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator/(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // divide real by complex
|
||
|
_CMPLX(_Ty) _Tmp(_Left);
|
||
|
return (_Tmp /= _Right);
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION UNARY operator+
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator+(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return +complex
|
||
|
return (_CMPLX(_Ty)(_Left));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION UNARY operator-
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl operator-(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return -complex
|
||
|
return (_CMPLX(_Ty)(-real(_Left), -imag(_Left)));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator==
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator==(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // test complex equal to complex
|
||
|
return (real(_Left) == real(_Right) && imag(_Left) == imag(_Right));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator==(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // test real equal to complex
|
||
|
return (real(_Left) == _Right && imag(_Left) == 0);
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator==(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // test complex equal to real
|
||
|
return (_Left == real(_Right) && 0 == imag(_Right));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION operator!=
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator!=(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // test complex not equal to complex
|
||
|
return (!(_Left == _Right));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator!=(const _CMPLX(_Ty)& _Left,
|
||
|
const _Ty& _Right)
|
||
|
{ // test real not equal to complex
|
||
|
return (!(_Left == _Right));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
bool __cdecl operator!=(const _Ty& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // test complex not equal to real
|
||
|
return (!(_Left == _Right));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION abs
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl abs(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return |complex| as real
|
||
|
int _Leftexp;
|
||
|
_Ty _Rho = _Fabs(_Left, &_Leftexp); // get magnitude and scale factor
|
||
|
|
||
|
if (_Leftexp == 0)
|
||
|
return (_Rho); // no scale factor
|
||
|
else
|
||
|
return (_CTR(_Ty)::ldexp(_Rho, _Leftexp)); // scale result
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION arg
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl arg(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return phase angle of complex as real
|
||
|
return (_CTR(_Ty)::atan2(imag(_Left), real(_Left)));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION conj
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl conj(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return complex conjugate
|
||
|
return (_CMPLX(_Ty)(real(_Left), -imag(_Left)));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION cos
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl cos(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return cos(complex)
|
||
|
return (_CMPLX(_Ty)(
|
||
|
_CTR(_Ty)::_Cosh(imag(_Left), _CTR(_Ty)::cos(real(_Left))),
|
||
|
-_CTR(_Ty)::_Sinh(imag(_Left),
|
||
|
_CTR(_Ty)::sin(real(_Left)))));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION cosh
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl cosh(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return cosh(complex)
|
||
|
return (_CMPLX(_Ty)(
|
||
|
_CTR(_Ty)::_Cosh(real(_Left), _CTR(_Ty)::cos(imag(_Left))),
|
||
|
_CTR(_Ty)::_Sinh(real(_Left), _CTR(_Ty)::sin(imag(_Left)))));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION exp
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl exp(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return exp(complex)
|
||
|
_Ty _Real(real(_Left)), _Imag(real(_Left));
|
||
|
_CTR(_Ty)::_Exp(&_Real, _CTR(_Ty)::cos(imag(_Left)), 0);
|
||
|
_CTR(_Ty)::_Exp(&_Imag, _CTR(_Ty)::sin(imag(_Left)), 0);
|
||
|
return (_CMPLX(_Ty)(_Real, _Imag));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION log
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl log(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return log(complex)
|
||
|
_Ty _Theta = _CTR(_Ty)::atan2(imag(_Left), real(_Left)); // get phase
|
||
|
|
||
|
if (_CTR(_Ty)::_Isnan(_Theta))
|
||
|
return (_CMPLX(_Ty)(_Theta, _Theta)); // real or imag is NaN
|
||
|
else
|
||
|
{ // use 1 1/2 precision to preserve bits
|
||
|
static const _Ty _Cm = (_Ty)(22713.0L / 32768.0L);
|
||
|
static const _Ty _Cl = (_Ty)1.4286068203094172321214581765680755e-6L;
|
||
|
int _Leftexp;
|
||
|
_Ty _Rho = _Fabs(_Left, &_Leftexp); // get magnitude and scale factor
|
||
|
|
||
|
_Ty _Leftn = (_Ty)_Leftexp;
|
||
|
_CMPLX(_Ty) _Tmp(
|
||
|
_Rho == 0 ? -_CTR(_Ty)::_Infv(_Rho) // log(0) == -INF
|
||
|
: _CTR(_Ty)::_Isinf(_Rho) ? _Rho // log(INF) == INF
|
||
|
: _CTR(_Ty)::log(_Rho) + _Leftn * _Cl + _Leftn * _Cm,
|
||
|
_Theta);
|
||
|
return (_Tmp);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION log10
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl log10(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return log10(complex)
|
||
|
return (log(_Left) * (_Ty)0.43429448190325182765112891891660508L);
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION norm
|
||
|
_TMPLT(_Ty) inline
|
||
|
_Ty __cdecl norm(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return squared magnitude
|
||
|
return (real(_Left) * real(_Left) + imag(_Left) * imag(_Left));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION polar
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl polar(const _Ty& _Rho, const _Ty& _Theta)
|
||
|
{ // return _Rho * exp(i * _Theta) as complex
|
||
|
return (_CMPLX(_Ty)(_Rho * _CTR(_Ty)::cos(_Theta),
|
||
|
_Rho * _CTR(_Ty)::sin(_Theta)));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl polar(const _Ty& _Rho)
|
||
|
{ // return _Rho * exp(i * 0) as complex
|
||
|
return (_CMPLX(_Ty)(_Rho, (_Ty)0));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION pow
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl pow(const _CMPLX(_Ty)& _Left, const _Ty& _Right)
|
||
|
{ // return complex ^ real
|
||
|
if (imag(_Left) == 0 && 0 <= real(_Left))
|
||
|
return (_CMPLX(_Ty)(_CTR(_Ty)::pow(real(_Left), _Right)));
|
||
|
else
|
||
|
return (exp(_Right * log(_Left)));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl pow(const _CMPLX(_Ty)& _Left, int _Right)
|
||
|
{ // return complex ^ integer
|
||
|
_CMPLX(_Ty) _Tmp = _Left;
|
||
|
unsigned int _Count = _Right;
|
||
|
|
||
|
if (_Right < 0)
|
||
|
_Count = 0 - _Count; // safe negation as unsigned
|
||
|
|
||
|
for (_CMPLX(_Ty) _Zv = _CMPLX(_Ty)(1); ; _Tmp *= _Tmp)
|
||
|
{ // fold in _Left ^ (2 ^ _Count) as needed
|
||
|
if ((_Count & 1) != 0)
|
||
|
_Zv *= _Tmp;
|
||
|
if ((_Count >>= 1) == 0)
|
||
|
return (_Right < 0 ? _CMPLX(_Ty)(1) / _Zv : _Zv);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl pow(const _Ty& _Left, const _CMPLX(_Ty)& _Right)
|
||
|
{ // return real ^ complex
|
||
|
if (imag(_Right) == 0)
|
||
|
return (_CMPLX(_Ty)(_CTR(_Ty)::pow(_Left, real(_Right))));
|
||
|
else
|
||
|
return (exp(_Right * _CTR(_Ty)::log(_Left)));
|
||
|
}
|
||
|
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl pow(const _CMPLX(_Ty)& _Left,
|
||
|
const _CMPLX(_Ty)& _Right)
|
||
|
{ // return complex ^ complex
|
||
|
if (imag(_Right) == 0)
|
||
|
return (pow(_Left, real(_Right)));
|
||
|
else if (imag(_Left) == 0)
|
||
|
return (_CMPLX(_Ty)(pow(real(_Left), _Right)));
|
||
|
else
|
||
|
return (exp(_Right * log(_Left)));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION sin
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl sin(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return sin(complex)
|
||
|
return (_CMPLX(_Ty)(
|
||
|
_CTR(_Ty)::_Cosh(imag(_Left), _CTR(_Ty)::sin(real(_Left))),
|
||
|
_CTR(_Ty)::_Sinh(imag(_Left), _CTR(_Ty)::cos(real(_Left)))));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION sinh
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl sinh(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return sinh(complex)
|
||
|
return (_CMPLX(_Ty)(
|
||
|
_CTR(_Ty)::_Sinh(real(_Left), _CTR(_Ty)::cos(imag(_Left))),
|
||
|
_CTR(_Ty)::_Cosh(real(_Left), _CTR(_Ty)::sin(imag(_Left)))));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION sqrt
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl sqrt(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return sqrt(complex)
|
||
|
int _Leftexp;
|
||
|
_Ty _Rho = _Fabs(_Left, &_Leftexp); // get magnitude and scale factor
|
||
|
|
||
|
if (_Leftexp == 0)
|
||
|
return (_CMPLX(_Ty)(_Rho, _Rho)); // argument is zero, INF, or NaN
|
||
|
else
|
||
|
{ // compute in safest quadrant
|
||
|
_Ty _Realmag = _CTR(_Ty)::ldexp(real(_Left) < 0
|
||
|
? - real(_Left) : real(_Left), -_Leftexp);
|
||
|
_Rho = _CTR(_Ty)::ldexp(_CTR(_Ty)::sqrt(
|
||
|
2 * (_Realmag + _Rho)), _Leftexp / 2 - 1);
|
||
|
|
||
|
if (0 <= real(_Left))
|
||
|
return (_CMPLX(_Ty)(_Rho, imag(_Left) / (2 * _Rho)));
|
||
|
else if (imag(_Left) < 0)
|
||
|
return (_CMPLX(_Ty)(-imag(_Left) / (2 * _Rho), -_Rho));
|
||
|
else
|
||
|
return (_CMPLX(_Ty)(imag(_Left) / (2 * _Rho), _Rho));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION tanh
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl tanh(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return tanh(complex)
|
||
|
_Ty _Tv = _CTR(_Ty)::tan(imag(_Left));
|
||
|
_Ty _Sv = _CTR(_Ty)::_Sinh(real(_Left), (_Ty)(1));
|
||
|
_Ty _Bv = _Sv *((_Ty)(1) + _Tv * _Tv);
|
||
|
_Ty _Dv = (_Ty)(1) + _Bv * _Sv;
|
||
|
return (_CMPLX(_Ty)((_CTR(_Ty)::sqrt((_Ty)(1) + _Sv * _Sv))
|
||
|
* _Bv / _Dv, _Tv / _Dv));
|
||
|
}
|
||
|
|
||
|
// TEMPLATE FUNCTION tan
|
||
|
_TMPLT(_Ty) inline
|
||
|
_CMPLX(_Ty) __cdecl tan(const _CMPLX(_Ty)& _Left)
|
||
|
{ // return tan(complex)
|
||
|
_CMPLX(_Ty) _Zv(tanh(_CMPLX(_Ty)(-imag(_Left), real(_Left))));
|
||
|
return (_CMPLX(_Ty)(imag(_Zv), -real(_Zv)));
|
||
|
}
|
||
|
|
||
|
#ifdef _DLL_CPPLIB
|
||
|
#ifndef CRTDLL2
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl imag(const complex<float>&);
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl real(const complex<float>&);
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl _Fabs(const complex<float>&, int *);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator+(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator+(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator+(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator-(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator-(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator-(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator*(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator*(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator*(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator/(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator/(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator/(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator+(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl operator-(const complex<float>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl abs(const complex<float>&);
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl arg(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl conj(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl cos(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl cosh(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl exp(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl log(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl log10(const complex<float>&);
|
||
|
template _CRTIMP2 float
|
||
|
__cdecl norm(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl polar(const float&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl polar(const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl pow(const complex<float>&, const float&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl pow(const complex<float>&, int);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl pow(const float&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl pow(const complex<float>&, const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl sin(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl sinh(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl sqrt(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl tanh(const complex<float>&);
|
||
|
template _CRTIMP2 complex<float>
|
||
|
__cdecl tan(const complex<float>&);
|
||
|
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl imag(const complex<double>&);
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl real(const complex<double>&);
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl _Fabs(const complex<double>&, int *);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator+(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator+(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator+(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator-(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator-(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator-(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator*(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator*(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator*(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator/(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator/(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator/(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator+(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl operator-(const complex<double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl abs(const complex<double>&);
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl arg(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl conj(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl cos(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl cosh(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl exp(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl log(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl log10(const complex<double>&);
|
||
|
template _CRTIMP2 double
|
||
|
__cdecl norm(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl polar(const double&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl polar(const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl pow(const complex<double>&, const double&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl pow(const complex<double>&, int);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl pow(const double&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl pow(const complex<double>&, const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl sin(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl sinh(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl sqrt(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl tanh(const complex<double>&);
|
||
|
template _CRTIMP2 complex<double>
|
||
|
__cdecl tan(const complex<double>&);
|
||
|
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl imag(const complex<long double>&);
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl real(const complex<long double>&);
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl _Fabs(const complex<long double>&, int *);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator+(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator+(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator+(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator-(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator-(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator-(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator*(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator*(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator*(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator/(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator/(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator/(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator+(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl operator-(const complex<long double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator==(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<long double>&,
|
||
|
const complex<long double>&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 bool
|
||
|
__cdecl operator!=(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl abs(const complex<long double>&);
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl arg(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl conj(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl cos(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl cosh(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl exp(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl log(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl log10(const complex<long double>&);
|
||
|
template _CRTIMP2 long double
|
||
|
__cdecl norm(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl polar(const long double&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl polar(const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl pow(const complex<long double>&, const long double&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl pow(const complex<long double>&, int);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl pow(const long double&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl pow(const complex<long double>&, const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl sin(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl sinh(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl sqrt(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl tanh(const complex<long double>&);
|
||
|
template _CRTIMP2 complex<long double>
|
||
|
__cdecl tan(const complex<long double>&);
|
||
|
#endif // CRTDLL2
|
||
|
#endif // _DLL_CPPLIB
|
||
|
|
||
|
#undef _XCOMPLEX_ /* SIC: may be included multiple times */
|
||
|
#endif /* _XCOMPLEX_ */
|
||
|
|
||
|
/*
|
||
|
* Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
|
||
|
* Consult your license regarding permissions and restrictions.
|
||
|
V3.10:0009 */
|