mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
re-implementation complex transcendental functions
This commit is contained in:
parent
c830cab086
commit
22c3f6e132
32 changed files with 1460 additions and 486 deletions
84
sprout/complex/atanh.hpp
Normal file
84
sprout/complex/atanh.hpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*=============================================================================
|
||||
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_ATANH_HPP
|
||||
#define SPROUT_COMPLEX_ATANH_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/math/log.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/complex/complex.hpp>
|
||||
#include <sprout/complex/log.hpp>
|
||||
#include <sprout/complex/sqrt.hpp>
|
||||
|
||||
#include <sprout/complex/operators.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// atanh
|
||||
//
|
||||
// G.6.2.3 The catanh functions
|
||||
// catanh(conj(z)) = conj(catanh(z)) and catanh is odd.
|
||||
// catanh(+0 + i0) returns +0 + i0.
|
||||
// catanh(+0 + iNaN) returns +0 + iNaN.
|
||||
// catanh(+1 + i0) returns +<2B>‡+ i0 and raises the <20>e<EFBFBD>edivide-by-zero<72>f<EFBFBD>f floating-point exception.
|
||||
// catanh(x + i<>‡) returns +0 + ip /2, for finite positive-signed x.
|
||||
// catanh(x + iNaN) returns NaN + iNaN and optionally raises the <20>e<EFBFBD>einvalid<69>f<EFBFBD>f floating-point exception, for nonzero finite x.
|
||||
// catanh(+<2B>‡+ iy) returns +0 + ip /2, for finite positive-signed y.
|
||||
// catanh(+<2B>‡+ i<>‡) returns +0 + ip /2.
|
||||
// catanh(+<2B>‡+ iNaN) returns +0 + iNaN.
|
||||
// catanh(NaN + iy) returns NaN + iNaN and optionally raises the <20>e<EFBFBD>einvalid<69>f<EFBFBD>f floating-point exception, for finite y.
|
||||
// catanh(NaN + i<>‡) returns <20>}0 + ip /2 (where the sign of the real part of the result is unspecified).
|
||||
// catanh(NaN + iNaN) returns NaN + iNaN.
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::complex<T>
|
||||
atanh_impl_1(sprout::complex<T> const& x, T const& i2, T const& z, T const& num, T const& den) {
|
||||
return sprout::complex<T>(
|
||||
sprout::math::quarter<T>() * (sprout::math::log(i2 + num * num) - sprout::math::log(i2 + den * den)),
|
||||
sprout::math::half<T>() * sprout::math::atan2(T(2) * x.imag(), z)
|
||||
);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::complex<T>
|
||||
atanh_impl(sprout::complex<T> const& x, T const& i2) {
|
||||
return sprout::detail::atanh_impl_1(
|
||||
x, i2,
|
||||
T(1) - i2 - x.real() * x.real(),
|
||||
T(1) + x.imag(), T(1) - x.imag()
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::complex<T>
|
||||
atanh(sprout::complex<T> const& x) {
|
||||
typedef sprout::complex<T> type;
|
||||
return sprout::math::isnan(x.real())
|
||||
? sprout::math::isnan(x.imag()) ? type(x.imag(), x.imag())
|
||||
: sprout::math::isinf(x.imag()) ? type(sprout::math::copysign(T(0), x.real()), sprout::math::copysign(sprout::math::half_pi<T>(), x.imag()))
|
||||
: type(x.real(), x.real())
|
||||
: sprout::math::isnan(x.imag())
|
||||
? sprout::math::isinf(x.real()) ? type(sprout::math::copysign(T(0), x.real()), x.imag())
|
||||
: x.real() == 0 ? x
|
||||
: type(x.imag(), x.imag())
|
||||
: sprout::math::isinf(x.real()) || sprout::math::isinf(x.imag())
|
||||
? type(sprout::math::copysign(T(0), x.real()), sprout::math::copysign(sprout::math::half_pi<T>(), x.imag()))
|
||||
: x.real() == 0 && x.imag() == 0 ? x
|
||||
: (x.real() == 1 || x.real() == -1) && x.imag() == 0 ? type(sprout::math::copysign(sprout::numeric_limits<T>::infinity(), x.real()), x.imag())
|
||||
// : sprout::detail::atanh_impl(x, x.imag() * x.imag())
|
||||
: (sprout::log(T(1) + x) - sprout::log(T(1) - x)) / T(2)
|
||||
;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPLEX_ATANH_HPP
|
Loading…
Add table
Add a link
Reference in a new issue