fix doc example typo
[boost.git] / boost / tr1 / complex.hpp
blob392c69ab02ead09ab22990090218c66f169add61
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)
6 #ifndef BOOST_TR1_COMPLEX_HPP_INCLUDED
7 # define BOOST_TR1_COMPLEX_HPP_INCLUDED
8 # include <boost/tr1/detail/config.hpp>
9 # include <complex>
11 #ifndef BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG
13 #include <boost/math/complex.hpp>
15 namespace std {
16 namespace tr1 {
18 using boost::math::acos;
19 using boost::math::asin;
20 using boost::math::atan;
21 using boost::math::acosh;
22 using boost::math::asinh;
23 using boost::math::atanh;
24 using boost::math::fabs;
26 } }
28 #else
30 # ifdef BOOST_HAS_INCLUDE_NEXT
31 # include_next BOOST_TR1_HEADER(complex)
32 # else
33 # include <boost/tr1/detail/config_all.hpp>
34 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))
35 # endif
37 #endif
39 #ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS
41 #include <boost/tr1/detail/math_overloads.hpp>
42 #include <boost/assert.hpp>
43 #include <boost/detail/workaround.hpp>
44 #include <boost/config/no_tr1/cmath.hpp>
46 namespace std{
48 #ifdef BOOST_NO_STDC_NAMESPACE
49 using :: atan2;
50 #endif
52 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
53 template <class T>
54 inline BOOST_TR1_MATH_RETURN(double) arg(const T& t)
56 return ::std::atan2(0.0, static_cast<double>(t));
58 #else
59 inline double arg(const double& t)
61 return ::std::atan2(0.0, t);
63 #endif
64 inline long double arg(const long double& t)
66 return ::std::atan2(0.0L, static_cast<long double>(t));
68 inline float arg(const float& t)
70 return ::std::atan2(0.0F, static_cast<float>(t));
73 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
74 template <class T>
75 inline BOOST_TR1_MATH_RETURN(double) norm(const T& t)
77 double r = static_cast<double>(t);
78 return r*r;
80 #else
81 inline double norm(const double& t)
83 return t*t;
85 #endif
86 inline long double norm(const long double& t)
88 long double l = t;
89 return l*l;
91 inline float norm(const float& t)
93 float f = t;
94 return f*f;
97 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
98 template <class T>
99 inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T& t)
101 return ::std::conj(std::complex<double>(static_cast<double>(t)));
103 #else
104 inline std::complex<double> conj(const double& t)
106 return ::std::conj(std::complex<double>(t));
108 #endif
109 inline std::complex<long double> conj(const long double& t)
111 return ::std::conj(std::complex<long double>(t));
113 inline std::complex<float> conj(const float& t)
115 std::complex<float> ct(t);
116 ct = ::std::conj(ct);
117 return ct;
120 #if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) && !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
121 inline complex<double> polar(const char& rho, const char& theta = 0)
122 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
123 inline complex<double> polar(const unsigned char& rho, const unsigned char& theta = 0)
124 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
125 inline complex<double> polar(const signed char& rho, const signed char& theta = 0)
126 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
127 inline complex<double> polar(const short& rho, const short& theta = 0)
128 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
129 inline complex<double> polar(const unsigned short& rho, const unsigned short& theta = 0)
130 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
131 inline complex<double> polar(const int& rho, const int& theta = 0)
132 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
133 inline complex<double> polar(const unsigned int& rho, const unsigned int& theta = 0)
134 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
135 inline complex<double> polar(const long& rho, const long& theta = 0)
136 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
137 inline complex<double> polar(const unsigned long& rho, const unsigned long& theta = 0)
138 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
139 #ifdef BOOST_HAS_LONG_LONG
140 inline complex<double> polar(const long long& rho, const long long& theta = 0)
141 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
142 inline complex<double> polar(const unsigned long long& rho, const unsigned long long& theta = 0)
143 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
144 #elif defined(BOOST_HAS_MS_INT64)
145 inline complex<double> polar(const __int64& rho, const __int64& theta = 0)
146 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
147 inline complex<double> polar(const unsigned __int64& rho, const unsigned __int64& theta = 0)
148 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
149 #endif
151 template<class T, class U>
152 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
153 polar(const T& rho, const U& theta)
155 typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
156 return std::polar(static_cast<real_type>(rho), static_cast<real_type>(theta));
158 #endif
160 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
161 template <class T>
162 inline BOOST_TR1_MATH_RETURN(double) imag(const T& )
164 return 0;
166 #else
167 inline double imag(const double& )
169 return 0;
171 #endif
172 inline long double imag(const long double& )
174 return 0;
176 inline float imag(const float& )
178 return 0;
181 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
182 template <class T>
183 inline BOOST_TR1_MATH_RETURN(double) real(const T& t)
185 return static_cast<double>(t);
187 #else
188 inline double real(const double& t)
190 return t;
192 #endif
193 inline long double real(const long double& t)
195 return t;
197 inline float real(const float& t)
199 return t;
202 template<class T, class U>
203 inline complex<typename boost::tr1_detail::largest_real<T, U>::type>
204 pow(const complex<T>& x, const complex<U>& y)
206 typedef complex<typename boost::tr1_detail::largest_real<T, U>::type> result_type;
207 typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
208 typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast2_type;
209 cast1_type x1(x);
210 cast2_type y1(y);
211 return std::pow(x1, y1);
213 template<class T, class U>
214 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
215 pow (const complex<T>& x, const U& y)
217 typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
218 typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
219 typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
220 real_type r = y;
221 cast1_type x1(x);
222 std::complex<real_type> y1(r);
223 return std::pow(x1, y1);
226 template<class T, class U>
227 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
228 pow (const T& x, const complex<U>& y)
230 typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
231 typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
232 typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast_type;
233 real_type r = x;
234 std::complex<real_type> x1(r);
235 cast_type y1(y);
236 return std::pow(x1, y1);
241 #endif
243 #endif