Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/tr1/complex.hpp @ 44

Last change on this file since 44 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 7.2 KB
Line 
1//  (C) Copyright John Maddock 2005.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_TR1_COMPLEX_HPP_INCLUDED
7#  define BOOST_TR1_COMPLEX_HPP_INCLUDED
8#  include <boost/tr1/detail/config.hpp>
9#  include <complex>
10
11#ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS
12
13#include <boost/tr1/detail/math_overloads.hpp>
14#include <boost/assert.hpp>
15#include <boost/detail/workaround.hpp>
16#include <cmath>
17
18namespace std{ 
19
20#ifdef BOOST_NO_STDC_NAMESPACE
21   using :: atan2;
22#endif
23
24#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
25template <class T>
26inline BOOST_TR1_MATH_RETURN(double) arg(const T& t)
27{
28   return ::std::atan2(0.0, static_cast<double>(t));
29}
30#else
31inline double arg(const double& t)
32{
33   return ::std::atan2(0.0, t);
34}
35#endif
36inline long double arg(const long double& t)
37{
38   return ::std::atan2(0.0L, static_cast<long double>(t));
39}
40inline float arg(const float& t)
41{
42   return ::std::atan2(0.0F, static_cast<float>(t));
43}
44
45#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
46template <class T>
47inline BOOST_TR1_MATH_RETURN(double) norm(const T& t)
48{
49   double r = static_cast<double>(t);
50   return r*r;
51}
52#else
53inline double norm(const double& t)
54{
55   return t*t;
56}
57#endif
58inline long double norm(const long double& t)
59{
60   long double l = t;
61   return l*l;
62}
63inline float norm(const float& t)
64{
65   float f = t;
66   return f*f;
67}
68
69#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
70template <class T>
71inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T& t)
72{
73   return ::std::conj(std::complex<double>(static_cast<double>(t)));
74}
75#else
76inline std::complex<double> conj(const double& t)
77{
78   return ::std::conj(std::complex<double>(t));
79}
80#endif
81inline std::complex<long double> conj(const long double& t)
82{
83   return ::std::conj(std::complex<long double>(t));
84}
85inline std::complex<float> conj(const float& t)
86{
87   std::complex<float> ct(t);
88   ct = ::std::conj(ct);
89   return ct;
90}
91
92#if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) && !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
93inline complex<double> polar(const char& rho, const char& theta = 0)
94{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
95inline complex<double> polar(const unsigned char& rho, const unsigned char& theta = 0)
96{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
97inline complex<double> polar(const signed char& rho, const signed char& theta = 0)
98{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
99inline complex<double> polar(const short& rho, const short& theta = 0)
100{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
101inline complex<double> polar(const unsigned short& rho, const unsigned short& theta = 0)
102{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
103inline complex<double> polar(const int& rho, const int& theta = 0)
104{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
105inline complex<double> polar(const unsigned int& rho, const unsigned int& theta = 0)
106{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
107inline complex<double> polar(const long& rho, const long& theta = 0)
108{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
109inline complex<double> polar(const unsigned long& rho, const unsigned long& theta = 0)
110{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
111#ifdef BOOST_HAS_LONG_LONG
112inline complex<double> polar(const long long& rho, const long long& theta = 0)
113{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
114inline complex<double> polar(const unsigned long long& rho, const unsigned long long& theta = 0)
115{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
116#elif defined(BOOST_HAS_MS_INT64)
117inline complex<double> polar(const __int64& rho, const __int64& theta = 0)
118{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
119inline complex<double> polar(const unsigned __int64& rho, const unsigned __int64& theta = 0)
120{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
121#endif
122
123template<class T, class U> 
124inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type> 
125   polar(const T& rho, const U& theta)
126{
127   typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
128   return std::polar(static_cast<real_type>(rho), static_cast<real_type>(theta));
129}
130#endif
131
132#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
133template <class T>
134inline BOOST_TR1_MATH_RETURN(double) imag(const T& )
135{
136   return 0;
137}
138#else
139inline double imag(const double& )
140{
141   return 0;
142}
143#endif
144inline long double imag(const long double& )
145{
146   return 0;
147}
148inline float imag(const float& )
149{
150   return 0;
151}
152
153#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
154template <class T>
155inline BOOST_TR1_MATH_RETURN(double) real(const T& t)
156{
157   return static_cast<double>(t);
158}
159#else
160inline double real(const double& t)
161{
162   return t;
163}
164#endif
165inline long double real(const long double& t)
166{
167   return t;
168}
169inline float real(const float& t)
170{
171   return t;
172}
173
174template<class T, class U>
175inline complex<typename boost::tr1_detail::largest_real<T, U>::type>
176   pow(const complex<T>& x, const complex<U>& y)
177{
178   typedef complex<typename boost::tr1_detail::largest_real<T, U>::type> result_type;
179   typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
180   typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast2_type;
181   cast1_type x1(x);
182   cast2_type y1(y);
183   return std::pow(x1, y1);
184}
185template<class T, class U> 
186inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
187   pow (const complex<T>& x, const U& y)
188{
189   typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
190   typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
191   typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
192   real_type r = y;
193   cast1_type x1(x);
194   std::complex<real_type> y1(r);
195   return std::pow(x1, y1);
196}
197
198template<class T, class U> 
199inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
200   pow (const T& x, const complex<U>& y)
201{
202   typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
203   typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
204   typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast_type;
205   real_type r = x;
206   std::complex<real_type> x1(r);
207   cast_type y1(y);
208   return std::pow(x1, y1);
209}
210
211}
212
213#endif
214
215#ifndef BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG
216
217#include <boost/math/complex.hpp>
218
219namespace std {
220namespace tr1 {
221
222using boost::math::acos;
223using boost::math::asin;
224using boost::math::atan;
225using boost::math::acosh;
226using boost::math::asinh;
227using boost::math::atanh;
228using boost::math::fabs;
229
230} }
231
232#else
233
234#  ifdef BOOST_HAS_INCLUDE_NEXT
235#     include_next BOOST_TR1_HEADER(complex)
236#  else
237#     include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))
238#  endif
239
240#endif
241
242#endif
243
Note: See TracBrowser for help on using the repository browser.