Update contrib.
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
20 # include "stlport_prefix.h"
21 // exp, log, pow for complex<float>, complex<double>, and complex<long double>
24 #include "complex_impl.h"
26 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
27 #include "libstdcppwsd.h"
32 //----------------------------------------------------------------------
35 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL
36 exp(const complex<float>& z)
38 float expx = _STLP_EXPF(z._M_re);
39 return complex<float>(expx * _STLP_COSF(z._M_im),
40 expx * _STLP_SINF(z._M_im));
43 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>& z)
45 double expx = _STLP_EXP(z._M_re);
46 return complex<double>(expx * _STLP_COS(z._M_im),
47 expx * _STLP_SIN(z._M_im));
50 # ifndef _STLP_NO_LONG_DOUBLE
51 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>& z)
53 long double expx = _STLP_EXPL(z._M_re);
54 return complex<long double>(expx * _STLP_COSL(z._M_im),
55 expx * _STLP_SINL(z._M_im));
59 //----------------------------------------------------------------------
62 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>& z)
66 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
67 get_complex_exp_float_ln10_inv() = 1.f / _STLP_LOGF(10.f);
68 r._M_im = _STLP_ATAN2F(z._M_im, z._M_re) * get_complex_exp_float_ln10_inv();
70 static float ln10_inv = 1.f / _STLP_LOGF(10.f);
71 r._M_im = _STLP_ATAN2F(z._M_im, z._M_re) * ln10_inv;
72 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
74 r._M_re = _STLP_LOG10F(_STLP_HYPOTF(z._M_re, z._M_im));
78 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>& z)
82 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
83 get_complex_exp_double_ln10_inv() = 1. / _STLP_LOG(10.);
84 r._M_im = _STLP_ATAN2(z._M_im, z._M_re) * get_complex_exp_double_ln10_inv();
86 static double ln10_inv = 1. / _STLP_LOG(10.);
87 r._M_im = _STLP_ATAN2(z._M_im, z._M_re) * ln10_inv;
88 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
90 r._M_re = _STLP_LOG10(_STLP_HYPOT(z._M_re, z._M_im));
94 #ifndef _STLP_NO_LONG_DOUBLE
95 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>& z)
97 complex<long double> result;
98 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
99 get_complex_exp_long_double_ln10_inv() = 1.l / _STLP_LOGL(10.l);
100 result._M_im = _STLP_ATAN2L(z._M_im, z._M_re) * get_complex_exp_long_double_ln10_inv();
102 static long double ln10_inv = 1.l / _STLP_LOGL(10.l);
103 result._M_im = _STLP_ATAN2L(z._M_im, z._M_re) * ln10_inv;
104 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
106 result._M_re = _STLP_LOG10L(_STLP_HYPOTL(z._M_re, z._M_im));
111 //----------------------------------------------------------------------
114 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL log(const complex<float>& z)
118 r._M_im = _STLP_ATAN2F(z._M_im, z._M_re);
119 r._M_re = _STLP_LOGF(_STLP_HYPOTF(z._M_re, z._M_im));
123 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>& z)
127 r._M_im = _STLP_ATAN2(z._M_im, z._M_re);
128 r._M_re = _STLP_LOG(_STLP_HYPOT(z._M_re, z._M_im));
132 #ifndef _STLP_NO_LONG_DOUBLE
133 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>& z)
135 complex<long double> result;
137 result._M_im = _STLP_ATAN2L(z._M_im, z._M_re);
138 result._M_re = _STLP_LOGL(_STLP_HYPOTL(z._M_re, z._M_im));
143 //----------------------------------------------------------------------
146 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL pow(const float& a, const complex<float>& b) {
147 float logr = _STLP_LOGF(a);
148 float x = _STLP_EXPF(logr*b._M_re);
149 float y = logr*b._M_im;
151 return complex<float>(x * _STLP_COSF(y), x * _STLP_SINF(y));
154 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& z_in, int n) {
155 complex<float> z = z_in;
156 z = __power(z, (n < 0 ? -n : n), multiplies< complex<float> >());
163 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& a, const float& b) {
164 float logr = _STLP_LOGF(_STLP_HYPOTF(a._M_re,a._M_im));
165 float logi = _STLP_ATAN2F(a._M_im, a._M_re);
166 float x = _STLP_EXPF(logr * b);
169 return complex<float>(x * _STLP_COSF(y), x * _STLP_SINF(y));
172 _STLP_EXP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& a, const complex<float>& b) {
173 float logr = _STLP_LOGF(_STLP_HYPOTF(a._M_re,a._M_im));
174 float logi = _STLP_ATAN2F(a._M_im, a._M_re);
175 float x = _STLP_EXPF(logr*b._M_re - logi*b._M_im);
176 float y = logr*b._M_im + logi*b._M_re;
178 return complex<float>(x * _STLP_COSF(y), x * _STLP_SINF(y));
182 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL pow(const double& a, const complex<double>& b) {
183 double logr = _STLP_LOG(a);
184 double x = _STLP_EXP(logr*b._M_re);
185 double y = logr*b._M_im;
187 return complex<double>(x * _STLP_COS(y), x * _STLP_SIN(y));
190 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& z_in, int n) {
191 complex<double> z = z_in;
192 z = __power(z, (n < 0 ? -n : n), multiplies< complex<double> >());
194 #if !defined(__SC__) //*TY 04/15/2000 -
196 #else //*TY 04/15/2000 - added workaround for SCpp compiler
197 return double(1.0) / z; //*TY 04/15/2000 - it incorrectly assign long double attribute to floating point literals
198 #endif //*TY 04/15/2000 -
203 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& a, const double& b) {
204 double logr = _STLP_LOG(_STLP_HYPOT(a._M_re,a._M_im));
205 double logi = _STLP_ATAN2(a._M_im, a._M_re);
206 double x = _STLP_EXP(logr * b);
209 return complex<double>(x * _STLP_COS(y), x * _STLP_SIN(y));
212 _STLP_EXP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& a, const complex<double>& b) {
213 double logr = _STLP_LOG(_STLP_HYPOT(a._M_re,a._M_im));
214 double logi = _STLP_ATAN2(a._M_im, a._M_re);
215 double x = _STLP_EXP(logr*b._M_re - logi*b._M_im);
216 double y = logr*b._M_im + logi*b._M_re;
218 return complex<double>(x * _STLP_COS(y), x * _STLP_SIN(y));
222 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL pow(const long double& a,
223 const complex<long double>& b) {
224 long double logr = _STLP_LOGL(a);
225 long double x = _STLP_EXPL(logr*b._M_re);
226 long double y = logr*b._M_im;
228 return complex<long double>(x * _STLP_COSL(y), x * _STLP_SINL(y));
231 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& z_in, int n) {
232 complex<long double> z = z_in;
233 z = __power(z, (n < 0 ? -n : n), multiplies< complex<long double> >());
240 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& a,
241 const long double& b) {
242 long double logr = _STLP_LOGL(_STLP_HYPOTL(a._M_re,a._M_im));
243 long double logi = _STLP_ATAN2L(a._M_im, a._M_re);
244 long double x = _STLP_EXPL(logr * b);
245 long double y = logi * b;
247 return complex<long double>(x * _STLP_COSL(y), x * _STLP_SINL(y));
250 _STLP_EXP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& a,
251 const complex<long double>& b) {
252 long double logr = _STLP_LOGL(_STLP_HYPOTL(a._M_re,a._M_im));
253 long double logi = _STLP_ATAN2L(a._M_im, a._M_re);
254 long double x = _STLP_EXPL(logr*b._M_re - logi*b._M_im);
255 long double y = logr*b._M_im + logi*b._M_re;
257 return complex<long double>(x * _STLP_COSL(y), x * _STLP_SINL(y));