Update contrib.
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>
11 #ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS
13 #include <boost/tr1/detail/math_overloads.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/detail/workaround.hpp>
20 #ifdef BOOST_NO_STDC_NAMESPACE
24 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
26 inline BOOST_TR1_MATH_RETURN(double) arg(const T& t)
28 return ::std::atan2(0.0, static_cast<double>(t));
31 inline double arg(const double& t)
33 return ::std::atan2(0.0, t);
36 inline long double arg(const long double& t)
38 return ::std::atan2(0.0L, static_cast<long double>(t));
40 inline float arg(const float& t)
42 return ::std::atan2(0.0F, static_cast<float>(t));
45 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
47 inline BOOST_TR1_MATH_RETURN(double) norm(const T& t)
49 double r = static_cast<double>(t);
53 inline double norm(const double& t)
58 inline long double norm(const long double& t)
63 inline float norm(const float& t)
69 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
71 inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T& t)
73 return ::std::conj(std::complex<double>(static_cast<double>(t)));
76 inline std::complex<double> conj(const double& t)
78 return ::std::conj(std::complex<double>(t));
81 inline std::complex<long double> conj(const long double& t)
83 return ::std::conj(std::complex<long double>(t));
85 inline std::complex<float> conj(const float& t)
87 std::complex<float> ct(t);
92 #if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) && !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
93 inline complex<double> polar(const char& rho, const char& theta = 0)
94 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
95 inline complex<double> polar(const unsigned char& rho, const unsigned char& theta = 0)
96 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
97 inline complex<double> polar(const signed char& rho, const signed char& theta = 0)
98 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
99 inline complex<double> polar(const short& rho, const short& theta = 0)
100 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
101 inline complex<double> polar(const unsigned short& rho, const unsigned short& theta = 0)
102 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
103 inline complex<double> polar(const int& rho, const int& theta = 0)
104 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
105 inline complex<double> polar(const unsigned int& rho, const unsigned int& theta = 0)
106 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
107 inline complex<double> polar(const long& rho, const long& theta = 0)
108 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
109 inline 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
112 inline complex<double> polar(const long long& rho, const long long& theta = 0)
113 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
114 inline 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)
117 inline complex<double> polar(const __int64& rho, const __int64& theta = 0)
118 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
119 inline complex<double> polar(const unsigned __int64& rho, const unsigned __int64& theta = 0)
120 { return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
123 template<class T, class U>
124 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
125 polar(const T& rho, const U& theta)
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));
132 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
134 inline BOOST_TR1_MATH_RETURN(double) imag(const T& )
139 inline double imag(const double& )
144 inline long double imag(const long double& )
148 inline float imag(const float& )
153 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
155 inline BOOST_TR1_MATH_RETURN(double) real(const T& t)
157 return static_cast<double>(t);
160 inline double real(const double& t)
165 inline long double real(const long double& t)
169 inline float real(const float& t)
174 template<class T, class U>
175 inline complex<typename boost::tr1_detail::largest_real<T, U>::type>
176 pow(const complex<T>& x, const complex<U>& y)
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;
183 return std::pow(x1, y1);
185 template<class T, class U>
186 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
187 pow (const complex<T>& x, const U& y)
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;
194 std::complex<real_type> y1(r);
195 return std::pow(x1, y1);
198 template<class T, class U>
199 inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
200 pow (const T& x, const complex<U>& y)
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;
206 std::complex<real_type> x1(r);
208 return std::pow(x1, y1);
215 #ifndef BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG
217 #include <boost/math/complex.hpp>
222 using boost::math::acos;
223 using boost::math::asin;
224 using boost::math::atan;
225 using boost::math::acosh;
226 using boost::math::asinh;
227 using boost::math::atanh;
228 using boost::math::fabs;
234 # ifdef BOOST_HAS_INCLUDE_NEXT
235 # include_next BOOST_TR1_HEADER(complex)
237 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))