123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED
- #define BOOST_MATH_COMPLEX_ATANH_INCLUDED
- #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
- # include <boost/math/complex/details.hpp>
- #endif
- #ifndef BOOST_MATH_LOG1P_INCLUDED
- # include <boost/math/special_functions/log1p.hpp>
- #endif
- #include <boost/assert.hpp>
- #ifdef BOOST_NO_STDC_NAMESPACE
- namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; }
- #endif
- namespace boost{ namespace math{
- template<class T>
- std::complex<T> atanh(const std::complex<T>& z)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- static const T pi = boost::math::constants::pi<T>();
- static const T half_pi = pi / 2;
- static const T one = static_cast<T>(1.0L);
- static const T two = static_cast<T>(2.0L);
- static const T four = static_cast<T>(4.0L);
- static const T zero = static_cast<T>(0);
- static const T log_two = boost::math::constants::ln_two<T>();
- #ifdef BOOST_MSVC
- #pragma warning(push)
- #pragma warning(disable:4127)
- #endif
- T x = std::fabs(z.real());
- T y = std::fabs(z.imag());
- T real, imag;
- T safe_upper = detail::safe_max(two);
- T safe_lower = detail::safe_min(static_cast<T>(2));
-
-
-
- if((boost::math::isnan)(x))
- {
- if((boost::math::isnan)(y))
- return std::complex<T>(x, x);
- else if((boost::math::isinf)(y))
- return std::complex<T>(0, ((boost::math::signbit)(z.imag()) ? -half_pi : half_pi));
- else
- return std::complex<T>(x, x);
- }
- else if((boost::math::isnan)(y))
- {
- if(x == 0)
- return std::complex<T>(x, y);
- if((boost::math::isinf)(x))
- return std::complex<T>(0, y);
- else
- return std::complex<T>(y, y);
- }
- else if((x > safe_lower) && (x < safe_upper) && (y > safe_lower) && (y < safe_upper))
- {
- T yy = y*y;
- T mxm1 = one - x;
-
-
-
-
-
- real = boost::math::log1p(four * x / (mxm1*mxm1 + yy));
- real /= four;
- if((boost::math::signbit)(z.real()))
- real = (boost::math::changesign)(real);
- imag = std::atan2((y * two), (mxm1*(one+x) - yy));
- imag /= two;
- if(z.imag() < 0)
- imag = (boost::math::changesign)(imag);
- }
- else
- {
-
-
-
-
-
-
-
-
- T mxm1 = one - x;
- if(x >= safe_upper)
- {
-
- if((boost::math::isinf)(x) || (boost::math::isinf)(y))
- {
- real = 0;
- }
- else if(y >= safe_upper)
- {
-
- real = boost::math::log1p((four/y) / (x/y + y/x));
- }
- else if(y > one)
- {
-
- real = boost::math::log1p(four / (x + y*y/x));
- }
- else
- {
-
- real = boost::math::log1p(four/x);
- }
- }
- else if(y >= safe_upper)
- {
- if(x > one)
- {
-
- real = boost::math::log1p((four*x/y) / (y + mxm1*mxm1/y));
- }
- else
- {
-
- real = four*x/y/y;
- }
- }
- else if (x != one)
- {
-
- T div = mxm1*mxm1;
- if(y > safe_lower)
- div += y*y;
- real = boost::math::log1p(four*x/div);
- }
- else
- real = boost::math::changesign(two * (std::log(y) - log_two));
- real /= four;
- if((boost::math::signbit)(z.real()))
- real = (boost::math::changesign)(real);
-
-
-
-
-
-
- if((x >= safe_upper) || (y >= safe_upper))
- {
- imag = pi;
- }
- else if(x <= safe_lower)
- {
-
-
-
-
- if(y <= safe_lower)
- imag = std::atan2(two*y, one);
- else
- {
- if((y == zero) && (x == zero))
- imag = 0;
- else
- imag = std::atan2(two*y, one - y*y);
- }
- }
- else
- {
-
-
-
- if((y == zero) && (x == one))
- imag = 0;
- else
- imag = std::atan2(two*y, mxm1*(one+x));
- }
- imag /= two;
- if((boost::math::signbit)(z.imag()))
- imag = (boost::math::changesign)(imag);
- }
- return std::complex<T>(real, imag);
- #ifdef BOOST_MSVC
- #pragma warning(pop)
- #endif
- }
- } }
- #endif
|