/*============================================================================= Copyright (c) 2011-2014 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_COMPLEX_TANH_HPP #define SPROUT_COMPLEX_TANH_HPP #include #include #include #include #include #include #include #include #include #include namespace sprout { // // tanh // // G.6.2.6 The ctanh functions // ctanh(conj(z)) = conj(ctanh(z))and ctanh is odd. // ctanh(+0 + i0) returns +0 + i0. // ctanh(x + i) returns NaN + iNaN and raises the eeinvalidff floating-point exception, for finite x. // ctanh(x + iNaN) returns NaN + iNaN and optionally raises the eeinvalidff floating-point exception, for finite x. // ctanh(++ iy) returns 1 + i0 sin(2y), for positive-signed finite y. // ctanh(++ i) returns 1 } i0 (where the sign of the imaginary part of the result is unspecified). // ctanh(++ iNaN) returns 1 } i0 (where the sign of the imaginary part of the result is unspecified). // ctanh(NaN + i0) returns NaN + i0. // ctanh(NaN + iy) returns NaN + iNaN and optionally raises the eeinvalidff floating-point exception, for all nonzero numbers y. // ctanh(NaN + iNaN) returns NaN + iNaN. // template inline SPROUT_CONSTEXPR sprout::complex tanh(sprout::complex const& x) { typedef sprout::complex type; return sprout::math::isnan(x.real()) ? sprout::math::isnan(x.imag()) ? x : x.imag() == 0 ? x : type(x.real(), x.real()) : sprout::math::isnan(x.imag()) ? sprout::math::isinf(x.real()) ? type(T(1), T(0)) : type(x.imag(), x.imag()) : sprout::math::isinf(x.real()) ? sprout::math::isinf(x.imag()) ? type(T(1), T(0)) : type(T(1), T(0) * sprout::math::sin(T(2) * x.imag())) : sprout::math::isinf(x.imag()) ? type(-sprout::numeric_limits::quiet_NaN(), -sprout::numeric_limits::quiet_NaN()) : x.real() == 0 && x.imag() == 0 ? x : sprout::sinh(x) / sprout::cosh(x) ; } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_TANH_HPP