atan.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #ifndef BOOST_MATH_COMPLEX_ATAN_INCLUDED
  6. #define BOOST_MATH_COMPLEX_ATAN_INCLUDED
  7. #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
  8. # include <boost/math/complex/details.hpp>
  9. #endif
  10. #ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED
  11. # include <boost/math/complex/atanh.hpp>
  12. #endif
  13. namespace boost{ namespace math{
  14. template<class T>
  15. std::complex<T> atan(const std::complex<T>& x)
  16. {
  17. //
  18. // We're using the C99 definition here; atan(z) = -i atanh(iz):
  19. //
  20. if(x.real() == 0)
  21. {
  22. if(x.imag() == 1)
  23. return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : static_cast<T>(HUGE_VAL));
  24. if(x.imag() == -1)
  25. return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : -static_cast<T>(HUGE_VAL));
  26. }
  27. return ::boost::math::detail::mult_minus_i(::boost::math::atanh(::boost::math::detail::mult_i(x)));
  28. }
  29. } } // namespaces
  30. #endif // BOOST_MATH_COMPLEX_ATAN_INCLUDED