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_MATH_COMPLEX_ATAN_INCLUDED
sl@0: #define BOOST_MATH_COMPLEX_ATAN_INCLUDED
sl@0: 
sl@0: #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
sl@0: #  include <boost/math/complex/details.hpp>
sl@0: #endif
sl@0: #ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED
sl@0: #  include <boost/math/complex/atanh.hpp>
sl@0: #endif
sl@0: 
sl@0: namespace boost{ namespace math{
sl@0: 
sl@0: template<class T> 
sl@0: std::complex<T> atan(const std::complex<T>& x)
sl@0: {
sl@0:    //
sl@0:    // We're using the C99 definition here; atan(z) = -i atanh(iz):
sl@0:    //
sl@0:    if(x.real() == 0)
sl@0:    {
sl@0:       if(x.imag() == 1)
sl@0:          return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : static_cast<T>(HUGE_VAL));
sl@0:       if(x.imag() == -1)
sl@0:          return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : -static_cast<T>(HUGE_VAL));
sl@0:    }
sl@0:    return ::boost::math::detail::mult_minus_i(::boost::math::atanh(::boost::math::detail::mult_i(x)));
sl@0: }
sl@0: 
sl@0: } } // namespaces
sl@0: 
sl@0: #endif // BOOST_MATH_COMPLEX_ATAN_INCLUDED