sl@0
|
1 |
// (C) Copyright John Maddock 2005.
|
sl@0
|
2 |
// Use, modification and distribution are subject to the
|
sl@0
|
3 |
// Boost Software License, Version 1.0. (See accompanying file
|
sl@0
|
4 |
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
|
sl@0
|
6 |
#ifndef BOOST_TR1_COMPLEX_HPP_INCLUDED
|
sl@0
|
7 |
# define BOOST_TR1_COMPLEX_HPP_INCLUDED
|
sl@0
|
8 |
# include <boost/tr1/detail/config.hpp>
|
sl@0
|
9 |
# include <complex>
|
sl@0
|
10 |
|
sl@0
|
11 |
#ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS
|
sl@0
|
12 |
|
sl@0
|
13 |
#include <boost/tr1/detail/math_overloads.hpp>
|
sl@0
|
14 |
#include <boost/assert.hpp>
|
sl@0
|
15 |
#include <boost/detail/workaround.hpp>
|
sl@0
|
16 |
#include <cmath>
|
sl@0
|
17 |
|
sl@0
|
18 |
namespace std{
|
sl@0
|
19 |
|
sl@0
|
20 |
#ifdef BOOST_NO_STDC_NAMESPACE
|
sl@0
|
21 |
using :: atan2;
|
sl@0
|
22 |
#endif
|
sl@0
|
23 |
|
sl@0
|
24 |
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
sl@0
|
25 |
template <class T>
|
sl@0
|
26 |
inline BOOST_TR1_MATH_RETURN(double) arg(const T& t)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
return ::std::atan2(0.0, static_cast<double>(t));
|
sl@0
|
29 |
}
|
sl@0
|
30 |
#else
|
sl@0
|
31 |
inline double arg(const double& t)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
return ::std::atan2(0.0, t);
|
sl@0
|
34 |
}
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
inline long double arg(const long double& t)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
return ::std::atan2(0.0L, static_cast<long double>(t));
|
sl@0
|
39 |
}
|
sl@0
|
40 |
inline float arg(const float& t)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
return ::std::atan2(0.0F, static_cast<float>(t));
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
sl@0
|
46 |
template <class T>
|
sl@0
|
47 |
inline BOOST_TR1_MATH_RETURN(double) norm(const T& t)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
double r = static_cast<double>(t);
|
sl@0
|
50 |
return r*r;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
#else
|
sl@0
|
53 |
inline double norm(const double& t)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return t*t;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
#endif
|
sl@0
|
58 |
inline long double norm(const long double& t)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
long double l = t;
|
sl@0
|
61 |
return l*l;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
inline float norm(const float& t)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
float f = t;
|
sl@0
|
66 |
return f*f;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
sl@0
|
70 |
template <class T>
|
sl@0
|
71 |
inline BOOST_TR1_MATH_RETURN(std::complex<double>) conj(const T& t)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
return ::std::conj(std::complex<double>(static_cast<double>(t)));
|
sl@0
|
74 |
}
|
sl@0
|
75 |
#else
|
sl@0
|
76 |
inline std::complex<double> conj(const double& t)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
return ::std::conj(std::complex<double>(t));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
#endif
|
sl@0
|
81 |
inline std::complex<long double> conj(const long double& t)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
return ::std::conj(std::complex<long double>(t));
|
sl@0
|
84 |
}
|
sl@0
|
85 |
inline std::complex<float> conj(const float& t)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
std::complex<float> ct(t);
|
sl@0
|
88 |
ct = ::std::conj(ct);
|
sl@0
|
89 |
return ct;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
#if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) && !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
|
sl@0
|
93 |
inline complex<double> polar(const char& rho, const char& theta = 0)
|
sl@0
|
94 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
95 |
inline complex<double> polar(const unsigned char& rho, const unsigned char& theta = 0)
|
sl@0
|
96 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
97 |
inline complex<double> polar(const signed char& rho, const signed char& theta = 0)
|
sl@0
|
98 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
99 |
inline complex<double> polar(const short& rho, const short& theta = 0)
|
sl@0
|
100 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
101 |
inline complex<double> polar(const unsigned short& rho, const unsigned short& theta = 0)
|
sl@0
|
102 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
103 |
inline complex<double> polar(const int& rho, const int& theta = 0)
|
sl@0
|
104 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
105 |
inline complex<double> polar(const unsigned int& rho, const unsigned int& theta = 0)
|
sl@0
|
106 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
107 |
inline complex<double> polar(const long& rho, const long& theta = 0)
|
sl@0
|
108 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
109 |
inline complex<double> polar(const unsigned long& rho, const unsigned long& theta = 0)
|
sl@0
|
110 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
111 |
#ifdef BOOST_HAS_LONG_LONG
|
sl@0
|
112 |
inline complex<double> polar(const long long& rho, const long long& theta = 0)
|
sl@0
|
113 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
114 |
inline complex<double> polar(const unsigned long long& rho, const unsigned long long& theta = 0)
|
sl@0
|
115 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
116 |
#elif defined(BOOST_HAS_MS_INT64)
|
sl@0
|
117 |
inline complex<double> polar(const __int64& rho, const __int64& theta = 0)
|
sl@0
|
118 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
119 |
inline complex<double> polar(const unsigned __int64& rho, const unsigned __int64& theta = 0)
|
sl@0
|
120 |
{ return ::std::polar(static_cast<double>(rho), static_cast<double>(theta)); }
|
sl@0
|
121 |
#endif
|
sl@0
|
122 |
|
sl@0
|
123 |
template<class T, class U>
|
sl@0
|
124 |
inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
|
sl@0
|
125 |
polar(const T& rho, const U& theta)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
|
sl@0
|
128 |
return std::polar(static_cast<real_type>(rho), static_cast<real_type>(theta));
|
sl@0
|
129 |
}
|
sl@0
|
130 |
#endif
|
sl@0
|
131 |
|
sl@0
|
132 |
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
sl@0
|
133 |
template <class T>
|
sl@0
|
134 |
inline BOOST_TR1_MATH_RETURN(double) imag(const T& )
|
sl@0
|
135 |
{
|
sl@0
|
136 |
return 0;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
#else
|
sl@0
|
139 |
inline double imag(const double& )
|
sl@0
|
140 |
{
|
sl@0
|
141 |
return 0;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
#endif
|
sl@0
|
144 |
inline long double imag(const long double& )
|
sl@0
|
145 |
{
|
sl@0
|
146 |
return 0;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
inline float imag(const float& )
|
sl@0
|
149 |
{
|
sl@0
|
150 |
return 0;
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
sl@0
|
154 |
template <class T>
|
sl@0
|
155 |
inline BOOST_TR1_MATH_RETURN(double) real(const T& t)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
return static_cast<double>(t);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
#else
|
sl@0
|
160 |
inline double real(const double& t)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
return t;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
#endif
|
sl@0
|
165 |
inline long double real(const long double& t)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
return t;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
inline float real(const float& t)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
return t;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
template<class T, class U>
|
sl@0
|
175 |
inline complex<typename boost::tr1_detail::largest_real<T, U>::type>
|
sl@0
|
176 |
pow(const complex<T>& x, const complex<U>& y)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
typedef complex<typename boost::tr1_detail::largest_real<T, U>::type> result_type;
|
sl@0
|
179 |
typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
|
sl@0
|
180 |
typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast2_type;
|
sl@0
|
181 |
cast1_type x1(x);
|
sl@0
|
182 |
cast2_type y1(y);
|
sl@0
|
183 |
return std::pow(x1, y1);
|
sl@0
|
184 |
}
|
sl@0
|
185 |
template<class T, class U>
|
sl@0
|
186 |
inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
|
sl@0
|
187 |
pow (const complex<T>& x, const U& y)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
|
sl@0
|
190 |
typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
|
sl@0
|
191 |
typedef typename boost::mpl::if_<boost::is_same<result_type, complex<T> >, result_type const&, result_type>::type cast1_type;
|
sl@0
|
192 |
real_type r = y;
|
sl@0
|
193 |
cast1_type x1(x);
|
sl@0
|
194 |
std::complex<real_type> y1(r);
|
sl@0
|
195 |
return std::pow(x1, y1);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
template<class T, class U>
|
sl@0
|
199 |
inline complex<typename boost::tr1_detail::promote_to_real<T, U>::type>
|
sl@0
|
200 |
pow (const T& x, const complex<U>& y)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
typedef typename boost::tr1_detail::promote_to_real<T, U>::type real_type;
|
sl@0
|
203 |
typedef complex<typename boost::tr1_detail::promote_to_real<T, U>::type> result_type;
|
sl@0
|
204 |
typedef typename boost::mpl::if_<boost::is_same<result_type, complex<U> >, result_type const&, result_type>::type cast_type;
|
sl@0
|
205 |
real_type r = x;
|
sl@0
|
206 |
std::complex<real_type> x1(r);
|
sl@0
|
207 |
cast_type y1(y);
|
sl@0
|
208 |
return std::pow(x1, y1);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
#endif
|
sl@0
|
214 |
|
sl@0
|
215 |
#ifndef BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG
|
sl@0
|
216 |
|
sl@0
|
217 |
#include <boost/math/complex.hpp>
|
sl@0
|
218 |
|
sl@0
|
219 |
namespace std {
|
sl@0
|
220 |
namespace tr1 {
|
sl@0
|
221 |
|
sl@0
|
222 |
using boost::math::acos;
|
sl@0
|
223 |
using boost::math::asin;
|
sl@0
|
224 |
using boost::math::atan;
|
sl@0
|
225 |
using boost::math::acosh;
|
sl@0
|
226 |
using boost::math::asinh;
|
sl@0
|
227 |
using boost::math::atanh;
|
sl@0
|
228 |
using boost::math::fabs;
|
sl@0
|
229 |
|
sl@0
|
230 |
} }
|
sl@0
|
231 |
|
sl@0
|
232 |
#else
|
sl@0
|
233 |
|
sl@0
|
234 |
# ifdef BOOST_HAS_INCLUDE_NEXT
|
sl@0
|
235 |
# include_next BOOST_TR1_HEADER(complex)
|
sl@0
|
236 |
# else
|
sl@0
|
237 |
# include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex))
|
sl@0
|
238 |
# endif
|
sl@0
|
239 |
|
sl@0
|
240 |
#endif
|
sl@0
|
241 |
|
sl@0
|
242 |
#endif
|
sl@0
|
243 |
|