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_INVERSE_TRIG |
12 | |
13 | #include <boost/math/complex.hpp> |
14 | |
15 | namespace std { |
16 | namespace tr1 { |
17 | |
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; |
25 | |
26 | } } |
27 | |
28 | #else |
29 | |
30 | # if defined(BOOST_HAS_INCLUDE_NEXT) && !defined(BOOST_TR1_DISABLE_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 |
36 | |
37 | #endif |
38 | |
39 | #ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS |
40 | |
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> |
45 | |
46 | namespace std{ |
47 | |
48 | #ifdef BOOST_NO_STDC_NAMESPACE |
49 | using :: atan2; |
50 | #endif |
51 | |
52 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
53 | template <class T> |
54 | inline BOOST_TR1_MATH_RETURN(double) arg(const T& t) |
55 | { |
56 | return ::std::atan2(0.0, static_cast<double>(t)); |
57 | } |
58 | #else |
59 | inline double arg(const double& t) |
60 | { |
61 | return ::std::atan2(0.0, t); |
62 | } |
63 | #endif |
64 | inline long double arg(const long double& t) |
65 | { |
66 | return ::std::atan2(0.0L, static_cast<long double>(t)); |
67 | } |
68 | inline float arg(const float& t) |
69 | { |
70 | return ::std::atan2(0.0F, static_cast<float>(t)); |
71 | } |
72 | |
73 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
74 | template <class T> |
75 | inline BOOST_TR1_MATH_RETURN(double) norm(const T& t) |
76 | { |
77 | double r = static_cast<double>(t); |
78 | return r*r; |
79 | } |
80 | #else |
81 | inline double norm(const double& t) |
82 | { |
83 | return t*t; |
84 | } |
85 | #endif |
86 | inline long double norm(const long double& t) |
87 | { |
88 | long double l = t; |
89 | return l*l; |
90 | } |
91 | inline float norm(const float& t) |
92 | { |
93 | float f = t; |
94 | return f*f; |
95 | } |
96 | |
97 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
98 | template <class T> |
99 | inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T& t) |
100 | { |
101 | return ::std::conj(std::complex<double>(static_cast<double>(t))); |
102 | } |
103 | #else |
104 | inline std::complex<double> conj(const double& t) |
105 | { |
106 | return ::std::conj(std::complex<double>(t)); |
107 | } |
108 | #endif |
109 | inline std::complex<long double> conj(const long double& t) |
110 | { |
111 | return ::std::conj(std::complex<long double>(t)); |
112 | } |
113 | inline std::complex<float> conj(const float& t) |
114 | { |
115 | std::complex<float> ct(t); |
116 | ct = ::std::conj(ct); |
117 | return ct; |
118 | } |
119 | |
120 | #if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) |
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 |
150 | |
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) |
154 | { |
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)); |
157 | } |
158 | #endif |
159 | |
160 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
161 | template <class T> |
162 | inline BOOST_TR1_MATH_RETURN(double) imag(const T& ) |
163 | { |
164 | return 0; |
165 | } |
166 | #else |
167 | inline double imag(const double& ) |
168 | { |
169 | return 0; |
170 | } |
171 | #endif |
172 | inline long double imag(const long double& ) |
173 | { |
174 | return 0; |
175 | } |
176 | inline float imag(const float& ) |
177 | { |
178 | return 0; |
179 | } |
180 | |
181 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
182 | template <class T> |
183 | inline BOOST_TR1_MATH_RETURN(double) real(const T& t) |
184 | { |
185 | return static_cast<double>(t); |
186 | } |
187 | #else |
188 | inline double real(const double& t) |
189 | { |
190 | return t; |
191 | } |
192 | #endif |
193 | inline long double real(const long double& t) |
194 | { |
195 | return t; |
196 | } |
197 | inline float real(const float& t) |
198 | { |
199 | return t; |
200 | } |
201 | |
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) |
205 | { |
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); |
212 | } |
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) |
216 | { |
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); |
224 | } |
225 | |
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) |
229 | { |
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); |
237 | } |
238 | |
239 | } |
240 | |
241 | #endif |
242 | |
243 | #endif |
244 | |
245 | |