mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
66 lines
2.9 KiB
C++
66 lines
2.9 KiB
C++
|
/*=============================================================================
|
|||
|
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_ASINH_HPP
|
|||
|
#define SPROUT_COMPLEX_ASINH_HPP
|
|||
|
|
|||
|
#include <sprout/config.hpp>
|
|||
|
#include <sprout/limits.hpp>
|
|||
|
#include <sprout/math/constants.hpp>
|
|||
|
#include <sprout/math/isnan.hpp>
|
|||
|
#include <sprout/math/isinf.hpp>
|
|||
|
#include <sprout/math/copysign.hpp>
|
|||
|
#include <sprout/complex/complex.hpp>
|
|||
|
#include <sprout/complex/log.hpp>
|
|||
|
#include <sprout/complex/sqrt.hpp>
|
|||
|
|
|||
|
namespace sprout {
|
|||
|
//
|
|||
|
// asinh
|
|||
|
//
|
|||
|
// G.6.2.2 The casinh functions
|
|||
|
// casinh(conj(z)) = conj(casinh(z)) and casinh is odd.
|
|||
|
// casinh(+0 + i0) returns 0 + i0.
|
|||
|
// casinh(x + i<><69>) returns +<2B><>+ ip /2 for positive-signed finite x.
|
|||
|
// casinh(x + iNaN) returns NaN + iNaN and optionally raises the <20>e<EFBFBD>einvalid<69>f<EFBFBD>f floating-point exception, for finite x.
|
|||
|
// casinh(+<2B><>+ iy) returns +<2B><>+ i0 for positive-signed finite y.
|
|||
|
// casinh(+<2B><>+ i<><69>) returns +<2B><>+ ip /4.
|
|||
|
// casinh(+<2B><>+ iNaN) returns +<2B><>+ iNaN.
|
|||
|
// casinh(NaN + i0) returns NaN + i0.
|
|||
|
// casinh(NaN + iy) returns NaN + iNaN and optionally raises the <20>e<EFBFBD>einvalid<69>f<EFBFBD>f floating-point exception, for finite nonzero y.
|
|||
|
// casinh(NaN + i<><69>) returns <20>}<7D><>+ iNaN (where the sign of the real part of the result is unspecified).
|
|||
|
// casinh(NaN + iNaN) returns NaN + iNaN.
|
|||
|
//
|
|||
|
template<typename T>
|
|||
|
inline SPROUT_CONSTEXPR sprout::complex<T>
|
|||
|
asinh(sprout::complex<T> const& x) {
|
|||
|
typedef sprout::complex<T> type;
|
|||
|
return sprout::math::isnan(x.real())
|
|||
|
? sprout::math::isnan(x.imag()) ? x
|
|||
|
: sprout::math::isinf(x.imag()) ? type(x.imag(), x.real())
|
|||
|
: x.imag() == 0 ? x
|
|||
|
: type(x.real(), x.real())
|
|||
|
: sprout::math::isnan(x.imag())
|
|||
|
? sprout::math::isinf(x.real()) ? x
|
|||
|
: type(sprout::math::copysign(sprout::numeric_limits<T>::quiet_NaN(), x.real()), x.imag())
|
|||
|
: sprout::math::isinf(x.real())
|
|||
|
? x.imag() == sprout::numeric_limits<T>::infinity() ? type(x.real(), sprout::math::quarter_pi<T>())
|
|||
|
: x.imag() == -sprout::numeric_limits<T>::infinity() ? type(x.real(), -sprout::math::quarter_pi<T>())
|
|||
|
: x.imag() == 0 ? x
|
|||
|
: type(x.real(), (x.imag() == 0 ? x.imag() : sprout::math::copysign(T(0), x.imag())))
|
|||
|
: sprout::math::isinf(x.imag()) ? type(
|
|||
|
sprout::math::copysign(sprout::numeric_limits<T>::infinity(), x.real()),
|
|||
|
sprout::math::copysign(sprout::math::half_pi<T>(), x.imag())
|
|||
|
)
|
|||
|
: x.real() == 0 && x.imag() == 0 ? x
|
|||
|
: sprout::log(sprout::sqrt(type((x.real() - x.imag()) * (x.real() + x.imag()) + T(1), T(2) * x.real() * x.imag())) + x)
|
|||
|
;
|
|||
|
}
|
|||
|
} // namespace sprout
|
|||
|
|
|||
|
#endif // #ifndef SPROUT_COMPLEX_ASINH_HPP
|