ReactOS 0.4.15-dev-8339-g4028de8
complex.cpp File Reference
#include "stlport_prefix.h"
#include <numeric>
#include <cmath>
#include <complex>
Include dependency graph for complex.cpp:

Go to the source code of this file.

Functions

_STLP_BEGIN_NAMESPACE _STLP_TEMPLATE_NULL _STLP_DECLSPEC float _STLP_CALL abs (const complex< float > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC double _STLP_CALL abs (const complex< double > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC long double _STLP_CALL abs (const complex< long double > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC float _STLP_CALL arg (const complex< float > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC double _STLP_CALL arg (const complex< double > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC long double _STLP_CALL arg (const complex< long double > &__z)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC complex< float > _STLP_CALL polar (const float &__rho, const float &__phi)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC complex< double > _STLP_CALL polar (const double &__rho, const double &__phi)
 
_STLP_TEMPLATE_NULL _STLP_DECLSPEC complex< long double > _STLP_CALL polar (const long double &__rho, const long double &__phi)
 
template<class _Tp >
static void _divT (const _Tp &__z1_r, const _Tp &__z1_i, const _Tp &__z2_r, const _Tp &__z2_i, _Tp &__res_r, _Tp &__res_i)
 
template<class _Tp >
static void _divT (const _Tp &__z1_r, const _Tp &__z2_r, const _Tp &__z2_i, _Tp &__res_r, _Tp &__res_i)
 
template<class _Tp >
static complex< _Tp > sqrtT (const complex< _Tp > &z)
 
complex< float > _STLP_CALL sqrt (const complex< float > &z)
 
complex< double > _STLP_CALL sqrt (const complex< double > &z)
 
complex< long double > _STLP_CALL sqrt (const complex< long double > &z)
 
template<class _Tp >
static complex< _Tp > expT (const complex< _Tp > &z)
 
_STLP_DECLSPEC complex< float > _STLP_CALL exp (const complex< float > &z)
 
_STLP_DECLSPEC complex< double > _STLP_CALL exp (const complex< double > &z)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL exp (const complex< long double > &z)
 
template<class _Tp >
static complex< _Tp > log10T (const complex< _Tp > &z, const _Tp &ln10_inv)
 
_STLP_DECLSPEC complex< float > _STLP_CALL log10 (const complex< float > &z)
 
_STLP_DECLSPEC complex< double > _STLP_CALL log10 (const complex< double > &z)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL log10 (const complex< long double > &z)
 
template<class _Tp >
static complex< _Tp > logT (const complex< _Tp > &z)
 
_STLP_DECLSPEC complex< float > _STLP_CALL log (const complex< float > &z)
 
_STLP_DECLSPEC complex< double > _STLP_CALL log (const complex< double > &z)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL log (const complex< long double > &z)
 
template<class _Tp >
static complex< _Tp > powT (const _Tp &a, const complex< _Tp > &b)
 
template<class _Tp >
static complex< _Tp > powT (const complex< _Tp > &z_in, int n)
 
template<class _Tp >
static complex< _Tp > powT (const complex< _Tp > &a, const _Tp &b)
 
template<class _Tp >
static complex< _Tp > powT (const complex< _Tp > &a, const complex< _Tp > &b)
 
_STLP_DECLSPEC complex< float > _STLP_CALL pow (const float &a, const complex< float > &b)
 
_STLP_DECLSPEC complex< float > _STLP_CALL pow (const complex< float > &z_in, int n)
 
_STLP_DECLSPEC complex< float > _STLP_CALL pow (const complex< float > &a, const float &b)
 
_STLP_DECLSPEC complex< float > _STLP_CALL pow (const complex< float > &a, const complex< float > &b)
 
_STLP_DECLSPEC complex< double > _STLP_CALL pow (const double &a, const complex< double > &b)
 
_STLP_DECLSPEC complex< double > _STLP_CALL pow (const complex< double > &z_in, int n)
 
_STLP_DECLSPEC complex< double > _STLP_CALL pow (const complex< double > &a, const double &b)
 
_STLP_DECLSPEC complex< double > _STLP_CALL pow (const complex< double > &a, const complex< double > &b)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL pow (const long double &a, const complex< long double > &b)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL pow (const complex< long double > &z_in, int n)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL pow (const complex< long double > &a, const long double &b)
 
_STLP_DECLSPEC complex< long double > _STLP_CALL pow (const complex< long double > &a, const complex< long double > &b)
 

Variables

static const float LN10_INVF = 1.f / ::log(10.f)
 
static const double LN10_INV = 1. / ::log10(10.)
 
static const long double LN10_INVL = 1.l / ::log(10.l)
 

Function Documentation

◆ _divT() [1/2]

template<class _Tp >
static void _divT ( const _Tp &  __z1_r,
const _Tp &  __z1_i,
const _Tp &  __z2_r,
const _Tp &  __z2_i,
_Tp &  __res_r,
_Tp &  __res_i 
)
static

Definition at line 84 of file complex.cpp.

86 {
87 _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
88 _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
89
90 if (__ar <= __ai) {
91 _Tp __ratio = __z2_r / __z2_i;
92 _Tp __denom = __z2_i * (1 + __ratio * __ratio);
93 __res_r = (__z1_r * __ratio + __z1_i) / __denom;
94 __res_i = (__z1_i * __ratio - __z1_r) / __denom;
95 }
96 else {
97 _Tp __ratio = __z2_i / __z2_r;
98 _Tp __denom = __z2_r * (1 + __ratio * __ratio);
99 __res_r = (__z1_r + __z1_i * __ratio) / __denom;
100 __res_i = (__z1_i - __z1_r * __ratio) / __denom;
101 }
102}

Referenced by complex< double >::_div(), and complex< float >::_div().

◆ _divT() [2/2]

template<class _Tp >
static void _divT ( const _Tp &  __z1_r,
const _Tp &  __z2_r,
const _Tp &  __z2_i,
_Tp &  __res_r,
_Tp &  __res_i 
)
static

Definition at line 105 of file complex.cpp.

107 {
108 _Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
109 _Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
110
111 if (__ar <= __ai) {
112 _Tp __ratio = __z2_r / __z2_i;
113 _Tp __denom = __z2_i * (1 + __ratio * __ratio);
114 __res_r = (__z1_r * __ratio) / __denom;
115 __res_i = - __z1_r / __denom;
116 }
117 else {
118 _Tp __ratio = __z2_i / __z2_r;
119 _Tp __denom = __z2_r * (1 + __ratio * __ratio);
120 __res_r = __z1_r / __denom;
121 __res_i = - (__z1_r * __ratio) / __denom;
122 }
123}

◆ abs() [1/3]

Definition at line 43 of file complex.cpp.

44{ return ::hypot(__z._M_re, __z._M_im); }
value_type _M_im
Definition: _complex.h:452
value_type _M_re
Definition: _complex.h:451

◆ abs() [2/3]

Definition at line 40 of file complex.cpp.

41{ return ::hypot(__z._M_re, __z._M_im); }
value_type _M_im
Definition: _complex.h:314
value_type _M_re
Definition: _complex.h:313

◆ abs() [3/3]

Definition at line 48 of file complex.cpp.

49{ return ::hypot(__z._M_re, __z._M_im); }

◆ arg() [1/3]

Definition at line 59 of file complex.cpp.

60{ return ::atan2(__z._M_im, __z._M_re); }

◆ arg() [2/3]

Definition at line 55 of file complex.cpp.

56{ return ::atan2(__z._M_im, __z._M_re); }

◆ arg() [3/3]

Definition at line 64 of file complex.cpp.

65{ return ::atan2(__z._M_im, __z._M_re); }

◆ exp() [1/3]

Definition at line 210 of file complex.cpp.

211{ return expT(z); }
static complex< _Tp > expT(const complex< _Tp > &z)
Definition: complex.cpp:202
GLdouble GLdouble z
Definition: glext.h:5874

◆ exp() [2/3]

Definition at line 207 of file complex.cpp.

208{ return expT(z); }

◆ exp() [3/3]

Definition at line 214 of file complex.cpp.

215{ return expT(z); }

◆ expT()

template<class _Tp >
static complex< _Tp > expT ( const complex< _Tp > &  z)
static

Definition at line 202 of file complex.cpp.

202 {
203 _Tp expx = ::exp(z._M_re);
204 return complex<_Tp>(expx * ::cos(z._M_im),
205 expx * ::sin(z._M_im));
206}
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
DWORD exp
Definition: msg.c:16058

Referenced by exp().

◆ log() [1/3]

Definition at line 256 of file complex.cpp.

257{ return logT(z); }
static complex< _Tp > logT(const complex< _Tp > &z)
Definition: complex.cpp:246

◆ log() [2/3]

Definition at line 253 of file complex.cpp.

254{ return logT(z); }

◆ log() [3/3]

Definition at line 260 of file complex.cpp.

261{ return logT(z); }

◆ log10() [1/3]

Definition at line 234 of file complex.cpp.

235{ return log10T(z, LN10_INV); }
static const double LN10_INV
Definition: complex.cpp:233
static complex< _Tp > log10T(const complex< _Tp > &z, const _Tp &ln10_inv)
Definition: complex.cpp:221

◆ log10() [2/3]

Definition at line 230 of file complex.cpp.

231{ return log10T(z, LN10_INVF); }
static const float LN10_INVF
Definition: complex.cpp:229

Referenced by log10T().

◆ log10() [3/3]

Definition at line 239 of file complex.cpp.

240{ return log10T(z, LN10_INVL); }
static const long double LN10_INVL
Definition: complex.cpp:238

◆ log10T()

template<class _Tp >
static complex< _Tp > log10T ( const complex< _Tp > &  z,
const _Tp &  ln10_inv 
)
static

Definition at line 221 of file complex.cpp.

221 {
223
224 r._M_im = ::atan2(z._M_im, z._M_re) * ln10_inv;
225 r._M_re = ::log10(::hypot(z._M_re, z._M_im));
226 return r;
227}
valarray< _Tp > atan2(const valarray< _Tp > &__x, const valarray< _Tp > &__y)
Definition: _valarray.h:928
_STLP_DECLSPEC complex< float > _STLP_CALL log10(const complex< float > &z)
Definition: complex.cpp:230
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
_Check_return_ __CRT_INLINE double hypot(_In_ double x, _In_ double y)
Definition: math.h:240

Referenced by log10().

◆ logT()

template<class _Tp >
static complex< _Tp > logT ( const complex< _Tp > &  z)
static

Definition at line 246 of file complex.cpp.

246 {
248
249 r._M_im = ::atan2(z._M_im, z._M_re);
250 r._M_re = ::log(::hypot(z._M_re, z._M_im));
251 return r;
252}
#define log(outFile, fmt,...)
Definition: util.h:15

Referenced by log().

◆ polar() [1/3]

Definition at line 73 of file complex.cpp.

74{ return complex<double>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }

◆ polar() [2/3]

Definition at line 70 of file complex.cpp.

71{ return complex<float>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }

◆ polar() [3/3]

Definition at line 78 of file complex.cpp.

79{ return complex<long double>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }

◆ pow() [1/12]

Definition at line 326 of file complex.cpp.

327{ return powT(a, b); }
static complex< _Tp > powT(const _Tp &a, const complex< _Tp > &b)
Definition: complex.cpp:267
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ pow() [2/12]

Definition at line 323 of file complex.cpp.

324{ return powT(a, b); }

◆ pow() [3/12]

_STLP_DECLSPEC complex< double > _STLP_CALL pow ( const complex< double > &  z_in,
int  n 
)

Definition at line 320 of file complex.cpp.

321{ return powT(z_in, n); }
GLdouble n
Definition: glext.h:7729

◆ pow() [4/12]

Definition at line 314 of file complex.cpp.

315{ return powT(a, b); }

◆ pow() [5/12]

Definition at line 311 of file complex.cpp.

312{ return powT(a, b); }

◆ pow() [6/12]

_STLP_DECLSPEC complex< float > _STLP_CALL pow ( const complex< float > &  z_in,
int  n 
)

Definition at line 308 of file complex.cpp.

309{ return powT(z_in, n); }

◆ pow() [7/12]

Definition at line 342 of file complex.cpp.

344{ return powT(a, b); }

◆ pow() [8/12]

Definition at line 338 of file complex.cpp.

340{ return powT(a, b); }

◆ pow() [9/12]

Definition at line 335 of file complex.cpp.

336{ return powT(z_in, n); }

◆ pow() [10/12]

Definition at line 317 of file complex.cpp.

318{ return powT(a, b); }

◆ pow() [11/12]

Definition at line 305 of file complex.cpp.

306{ return powT(a, b); }

◆ pow() [12/12]

Definition at line 330 of file complex.cpp.

332{ return powT(a, b); }

◆ powT() [1/4]

template<class _Tp >
static complex< _Tp > powT ( const _Tp &  a,
const complex< _Tp > &  b 
)
static

Definition at line 267 of file complex.cpp.

267 {
268 _Tp logr = ::log(a);
269 _Tp x = ::exp(logr * b._M_re);
270 _Tp y = logr * b._M_im;
271
272 return complex<_Tp>(x * ::cos(y), x * ::sin(y));
273}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548

Referenced by pow().

◆ powT() [2/4]

template<class _Tp >
static complex< _Tp > powT ( const complex< _Tp > &  a,
const _Tp &  b 
)
static

Definition at line 286 of file complex.cpp.

286 {
287 _Tp logr = ::log(::hypot(a._M_re,a._M_im));
288 _Tp logi = ::atan2(a._M_im, a._M_re);
289 _Tp x = ::exp(logr * b);
290 _Tp y = logi * b;
291
292 return complex<_Tp>(x * ::cos(y), x * ::sin(y));
293}
#define b
Definition: ke_i.h:79

◆ powT() [3/4]

template<class _Tp >
static complex< _Tp > powT ( const complex< _Tp > &  a,
const complex< _Tp > &  b 
)
static

Definition at line 296 of file complex.cpp.

296 {
297 _Tp logr = ::log(::hypot(a._M_re,a._M_im));
298 _Tp logi = ::atan2(a._M_im, a._M_re);
299 _Tp x = ::exp(logr * b._M_re - logi * b._M_im);
300 _Tp y = logr * b._M_im + logi * b._M_re;
301
302 return complex<_Tp>(x * ::cos(y), x * ::sin(y));
303}

◆ powT() [4/4]

template<class _Tp >
static complex< _Tp > powT ( const complex< _Tp > &  z_in,
int  n 
)
static

Definition at line 276 of file complex.cpp.

276 {
277 complex<_Tp> z = z_in;
278 z = _STLP_PRIV __power(z, (n < 0 ? -n : n), multiplies< complex<_Tp> >());
279 if (n < 0)
280 return _Tp(1.0) / z;
281 else
282 return z;
283}
#define _STLP_PRIV
Definition: _dm.h:70
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
Definition: _numeric.c:74

◆ sqrt() [1/3]

Definition at line 191 of file complex.cpp.

191{ return sqrtT(z); }
static complex< _Tp > sqrtT(const complex< _Tp > &z)
Definition: complex.cpp:167

◆ sqrt() [2/3]

◆ sqrt() [3/3]

Definition at line 195 of file complex.cpp.

195{ return sqrtT(z); }

◆ sqrtT()

template<class _Tp >
static complex< _Tp > sqrtT ( const complex< _Tp > &  z)
static

Definition at line 167 of file complex.cpp.

167 {
168 _Tp re = z._M_re;
169 _Tp im = z._M_im;
170 _Tp mag = ::hypot(re, im);
172
173 if (mag == 0.f) {
174 result._M_re = result._M_im = 0.f;
175 } else if (re > 0.f) {
176 result._M_re = ::sqrt(0.5f * (mag + re));
177 result._M_im = im/result._M_re/2.f;
178 } else {
179 result._M_im = ::sqrt(0.5f * (mag - re));
180 if (im < 0.f)
181 result._M_im = - result._M_im;
182 result._M_re = im/result._M_im/2.f;
183 }
184 return result;
185}
complex< float > _STLP_CALL sqrt(const complex< float > &z)
Definition: complex.cpp:188
GLuint64EXT * result
Definition: glext.h:11304

Referenced by sqrt().

Variable Documentation

◆ LN10_INV

const double LN10_INV = 1. / ::log10(10.)
static

Definition at line 233 of file complex.cpp.

Referenced by log10().

◆ LN10_INVF

const float LN10_INVF = 1.f / ::log(10.f)
static

Definition at line 229 of file complex.cpp.

Referenced by log10().

◆ LN10_INVL

const long double LN10_INVL = 1.l / ::log(10.l)
static

Definition at line 238 of file complex.cpp.

Referenced by log10().