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_INVERSE_TRIG
13 #include <boost/math/complex.hpp>
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
;
30 # ifdef BOOST_HAS_INCLUDE_NEXT
31 # include_next BOOST_TR1_HEADER(complex)
33 # include <boost/tr1/detail/config_all.hpp>
34 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))
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>
48 #ifdef BOOST_NO_STDC_NAMESPACE
52 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
54 inline BOOST_TR1_MATH_RETURN(double) arg(const T
& t
)
56 return ::std::atan2(0.0, static_cast<double>(t
));
59 inline double arg(const double& t
)
61 return ::std::atan2(0.0, t
);
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
75 inline BOOST_TR1_MATH_RETURN(double) norm(const T
& t
)
77 double r
= static_cast<double>(t
);
81 inline double norm(const double& t
)
86 inline long double norm(const long double& t
)
91 inline float norm(const float& t
)
97 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
99 inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T
& t
)
101 return ::std::conj(std::complex<double>(static_cast<double>(t
)));
104 inline std::complex<double> conj(const double& t
)
106 return ::std::conj(std::complex<double>(t
));
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
);
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
)); }
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
));
160 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
162 inline BOOST_TR1_MATH_RETURN(double) imag(const T
& )
167 inline double imag(const double& )
172 inline long double imag(const long double& )
176 inline float imag(const float& )
181 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
183 inline BOOST_TR1_MATH_RETURN(double) real(const T
& t
)
185 return static_cast<double>(t
);
188 inline double real(const double& t
)
193 inline long double real(const long double& t
)
197 inline float real(const float& 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
;
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
;
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
;
234 std::complex<real_type
> x1(r
);
236 return std::pow(x1
, y1
);