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 | |
---|
18 | namespace std{ |
---|
19 | |
---|
20 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
21 | using :: atan2; |
---|
22 | #endif |
---|
23 | |
---|
24 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
---|
25 | template <class T> |
---|
26 | inline BOOST_TR1_MATH_RETURN(double) arg(const T& t) |
---|
27 | { |
---|
28 | return ::std::atan2(0.0, static_cast<double>(t)); |
---|
29 | } |
---|
30 | #else |
---|
31 | inline double arg(const double& t) |
---|
32 | { |
---|
33 | return ::std::atan2(0.0, t); |
---|
34 | } |
---|
35 | #endif |
---|
36 | inline long double arg(const long double& t) |
---|
37 | { |
---|
38 | return ::std::atan2(0.0L, static_cast<long double>(t)); |
---|
39 | } |
---|
40 | inline 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 |
---|
46 | template <class T> |
---|
47 | inline BOOST_TR1_MATH_RETURN(double) norm(const T& t) |
---|
48 | { |
---|
49 | double r = static_cast<double>(t); |
---|
50 | return r*r; |
---|
51 | } |
---|
52 | #else |
---|
53 | inline double norm(const double& t) |
---|
54 | { |
---|
55 | return t*t; |
---|
56 | } |
---|
57 | #endif |
---|
58 | inline long double norm(const long double& t) |
---|
59 | { |
---|
60 | long double l = t; |
---|
61 | return l*l; |
---|
62 | } |
---|
63 | inline float norm(const float& t) |
---|
64 | { |
---|
65 | float f = t; |
---|
66 | return f*f; |
---|
67 | } |
---|
68 | |
---|
69 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
---|
70 | template <class T> |
---|
71 | inline 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 |
---|
76 | inline std::complex<double> conj(const double& t) |
---|
77 | { |
---|
78 | return ::std::conj(std::complex<double>(t)); |
---|
79 | } |
---|
80 | #endif |
---|
81 | inline std::complex<long double> conj(const long double& t) |
---|
82 | { |
---|
83 | return ::std::conj(std::complex<long double>(t)); |
---|
84 | } |
---|
85 | inline 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) |
---|
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)); } |
---|
121 | #endif |
---|
122 | |
---|
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) |
---|
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 |
---|
133 | template <class T> |
---|
134 | inline BOOST_TR1_MATH_RETURN(double) imag(const T& ) |
---|
135 | { |
---|
136 | return 0; |
---|
137 | } |
---|
138 | #else |
---|
139 | inline double imag(const double& ) |
---|
140 | { |
---|
141 | return 0; |
---|
142 | } |
---|
143 | #endif |
---|
144 | inline long double imag(const long double& ) |
---|
145 | { |
---|
146 | return 0; |
---|
147 | } |
---|
148 | inline float imag(const float& ) |
---|
149 | { |
---|
150 | return 0; |
---|
151 | } |
---|
152 | |
---|
153 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING |
---|
154 | template <class T> |
---|
155 | inline BOOST_TR1_MATH_RETURN(double) real(const T& t) |
---|
156 | { |
---|
157 | return static_cast<double>(t); |
---|
158 | } |
---|
159 | #else |
---|
160 | inline double real(const double& t) |
---|
161 | { |
---|
162 | return t; |
---|
163 | } |
---|
164 | #endif |
---|
165 | inline long double real(const long double& t) |
---|
166 | { |
---|
167 | return t; |
---|
168 | } |
---|
169 | inline float real(const float& t) |
---|
170 | { |
---|
171 | return t; |
---|
172 | } |
---|
173 | |
---|
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) |
---|
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 | } |
---|
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) |
---|
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 | |
---|
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) |
---|
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 | |
---|
219 | namespace std { |
---|
220 | namespace tr1 { |
---|
221 | |
---|
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; |
---|
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 | |
---|