sl@0: // (C) Copyright John Maddock 2005. sl@0: // Use, modification and distribution are subject to the sl@0: // Boost Software License, Version 1.0. (See accompanying file sl@0: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: #ifndef BOOST_TR1_COMPLEX_HPP_INCLUDED sl@0: # define BOOST_TR1_COMPLEX_HPP_INCLUDED sl@0: # include sl@0: # include sl@0: sl@0: #ifndef BOOST_HAS_TR1_COMPLEX_OVERLOADS sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace std{ sl@0: sl@0: #ifdef BOOST_NO_STDC_NAMESPACE sl@0: using :: atan2; sl@0: #endif sl@0: sl@0: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING sl@0: template sl@0: inline BOOST_TR1_MATH_RETURN(double) arg(const T& t) sl@0: { sl@0: return ::std::atan2(0.0, static_cast(t)); sl@0: } sl@0: #else sl@0: inline double arg(const double& t) sl@0: { sl@0: return ::std::atan2(0.0, t); sl@0: } sl@0: #endif sl@0: inline long double arg(const long double& t) sl@0: { sl@0: return ::std::atan2(0.0L, static_cast(t)); sl@0: } sl@0: inline float arg(const float& t) sl@0: { sl@0: return ::std::atan2(0.0F, static_cast(t)); sl@0: } sl@0: sl@0: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING sl@0: template sl@0: inline BOOST_TR1_MATH_RETURN(double) norm(const T& t) sl@0: { sl@0: double r = static_cast(t); sl@0: return r*r; sl@0: } sl@0: #else sl@0: inline double norm(const double& t) sl@0: { sl@0: return t*t; sl@0: } sl@0: #endif sl@0: inline long double norm(const long double& t) sl@0: { sl@0: long double l = t; sl@0: return l*l; sl@0: } sl@0: inline float norm(const float& t) sl@0: { sl@0: float f = t; sl@0: return f*f; sl@0: } sl@0: sl@0: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING sl@0: template sl@0: inline BOOST_TR1_MATH_RETURN(std::complex) conj(const T& t) sl@0: { sl@0: return ::std::conj(std::complex(static_cast(t))); sl@0: } sl@0: #else sl@0: inline std::complex conj(const double& t) sl@0: { sl@0: return ::std::conj(std::complex(t)); sl@0: } sl@0: #endif sl@0: inline std::complex conj(const long double& t) sl@0: { sl@0: return ::std::conj(std::complex(t)); sl@0: } sl@0: inline std::complex conj(const float& t) sl@0: { sl@0: std::complex ct(t); sl@0: ct = ::std::conj(ct); sl@0: return ct; sl@0: } sl@0: sl@0: #if !BOOST_WORKAROUND(__BORLANDC__, <=0x570) && !BOOST_WORKAROUND(BOOST_MSVC, < 1310) sl@0: inline complex polar(const char& rho, const char& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned char& rho, const unsigned char& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const signed char& rho, const signed char& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const short& rho, const short& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned short& rho, const unsigned short& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const int& rho, const int& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned int& rho, const unsigned int& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const long& rho, const long& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned long& rho, const unsigned long& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: #ifdef BOOST_HAS_LONG_LONG sl@0: inline complex polar(const long long& rho, const long long& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned long long& rho, const unsigned long long& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: #elif defined(BOOST_HAS_MS_INT64) sl@0: inline complex polar(const __int64& rho, const __int64& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: inline complex polar(const unsigned __int64& rho, const unsigned __int64& theta = 0) sl@0: { return ::std::polar(static_cast(rho), static_cast(theta)); } sl@0: #endif sl@0: sl@0: template sl@0: inline complex::type> sl@0: polar(const T& rho, const U& theta) sl@0: { sl@0: typedef typename boost::tr1_detail::promote_to_real::type real_type; sl@0: return std::polar(static_cast(rho), static_cast(theta)); sl@0: } sl@0: #endif sl@0: sl@0: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING sl@0: template sl@0: inline BOOST_TR1_MATH_RETURN(double) imag(const T& ) sl@0: { sl@0: return 0; sl@0: } sl@0: #else sl@0: inline double imag(const double& ) sl@0: { sl@0: return 0; sl@0: } sl@0: #endif sl@0: inline long double imag(const long double& ) sl@0: { sl@0: return 0; sl@0: } sl@0: inline float imag(const float& ) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING sl@0: template sl@0: inline BOOST_TR1_MATH_RETURN(double) real(const T& t) sl@0: { sl@0: return static_cast(t); sl@0: } sl@0: #else sl@0: inline double real(const double& t) sl@0: { sl@0: return t; sl@0: } sl@0: #endif sl@0: inline long double real(const long double& t) sl@0: { sl@0: return t; sl@0: } sl@0: inline float real(const float& t) sl@0: { sl@0: return t; sl@0: } sl@0: sl@0: template sl@0: inline complex::type> sl@0: pow(const complex& x, const complex& y) sl@0: { sl@0: typedef complex::type> result_type; sl@0: typedef typename boost::mpl::if_ >, result_type const&, result_type>::type cast1_type; sl@0: typedef typename boost::mpl::if_ >, result_type const&, result_type>::type cast2_type; sl@0: cast1_type x1(x); sl@0: cast2_type y1(y); sl@0: return std::pow(x1, y1); sl@0: } sl@0: template sl@0: inline complex::type> sl@0: pow (const complex& x, const U& y) sl@0: { sl@0: typedef typename boost::tr1_detail::promote_to_real::type real_type; sl@0: typedef complex::type> result_type; sl@0: typedef typename boost::mpl::if_ >, result_type const&, result_type>::type cast1_type; sl@0: real_type r = y; sl@0: cast1_type x1(x); sl@0: std::complex y1(r); sl@0: return std::pow(x1, y1); sl@0: } sl@0: sl@0: template sl@0: inline complex::type> sl@0: pow (const T& x, const complex& y) sl@0: { sl@0: typedef typename boost::tr1_detail::promote_to_real::type real_type; sl@0: typedef complex::type> result_type; sl@0: typedef typename boost::mpl::if_ >, result_type const&, result_type>::type cast_type; sl@0: real_type r = x; sl@0: std::complex x1(r); sl@0: cast_type y1(y); sl@0: return std::pow(x1, y1); sl@0: } sl@0: sl@0: } sl@0: sl@0: #endif sl@0: sl@0: #ifndef BOOST_HAS_TR1_COMPLEX_INVERSE_TRIG sl@0: sl@0: #include sl@0: sl@0: namespace std { sl@0: namespace tr1 { sl@0: sl@0: using boost::math::acos; sl@0: using boost::math::asin; sl@0: using boost::math::atan; sl@0: using boost::math::acosh; sl@0: using boost::math::asinh; sl@0: using boost::math::atanh; sl@0: using boost::math::fabs; sl@0: sl@0: } } sl@0: sl@0: #else sl@0: sl@0: # ifdef BOOST_HAS_INCLUDE_NEXT sl@0: # include_next BOOST_TR1_HEADER(complex) sl@0: # else sl@0: # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(complex)) sl@0: # endif sl@0: sl@0: #endif sl@0: sl@0: #endif sl@0: