mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-06-05 15:34:39 -04:00
Squashed 'boost/' content from commit b4feb19f2
git-subtree-dir: boost git-subtree-split: b4feb19f287ee92d87a9624b5d36b7cf46aeadeb
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// 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 BOOST_MATH_COMPLEX_ACOS_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ACOS_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_LOG1P_INCLUDED
|
||||
# include <boost/math/special_functions/log1p.hpp>
|
||||
#endif
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; }
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
std::complex<T> acos(const std::complex<T>& z)
|
||||
{
|
||||
//
|
||||
// This implementation is a transcription of the pseudo-code in:
|
||||
//
|
||||
// "Implementing the Complex Arcsine and Arccosine Functions using Exception Handling."
|
||||
// T E Hull, Thomas F Fairgrieve and Ping Tak Peter Tang.
|
||||
// ACM Transactions on Mathematical Software, Vol 23, No 3, Sept 1997.
|
||||
//
|
||||
|
||||
//
|
||||
// These static constants should really be in a maths constants library,
|
||||
// note that we have tweaked a_crossover as per: https://svn.boost.org/trac/boost/ticket/7290
|
||||
//
|
||||
static const T one = static_cast<T>(1);
|
||||
//static const T two = static_cast<T>(2);
|
||||
static const T half = static_cast<T>(0.5L);
|
||||
static const T a_crossover = static_cast<T>(10);
|
||||
static const T b_crossover = static_cast<T>(0.6417L);
|
||||
static const T s_pi = boost::math::constants::pi<T>();
|
||||
static const T half_pi = s_pi / 2;
|
||||
static const T log_two = boost::math::constants::ln_two<T>();
|
||||
static const T quarter_pi = s_pi / 4;
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127)
|
||||
#endif
|
||||
//
|
||||
// Get real and imaginary parts, discard the signs as we can
|
||||
// figure out the sign of the result later:
|
||||
//
|
||||
T x = std::fabs(z.real());
|
||||
T y = std::fabs(z.imag());
|
||||
|
||||
T real, imag; // these hold our result
|
||||
|
||||
//
|
||||
// Handle special cases specified by the C99 standard,
|
||||
// many of these special cases aren't really needed here,
|
||||
// but doing it this way prevents overflow/underflow arithmetic
|
||||
// in the main body of the logic, which may trip up some machines:
|
||||
//
|
||||
if((boost::math::isinf)(x))
|
||||
{
|
||||
if((boost::math::isinf)(y))
|
||||
{
|
||||
real = quarter_pi;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else if((boost::math::isnan)(y))
|
||||
{
|
||||
return std::complex<T>(y, -std::numeric_limits<T>::infinity());
|
||||
}
|
||||
else
|
||||
{
|
||||
// y is not infinity or nan:
|
||||
real = 0;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
}
|
||||
else if((boost::math::isnan)(x))
|
||||
{
|
||||
if((boost::math::isinf)(y))
|
||||
return std::complex<T>(x, ((boost::math::signbit)(z.imag())) ? std::numeric_limits<T>::infinity() : -std::numeric_limits<T>::infinity());
|
||||
return std::complex<T>(x, x);
|
||||
}
|
||||
else if((boost::math::isinf)(y))
|
||||
{
|
||||
real = half_pi;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else if((boost::math::isnan)(y))
|
||||
{
|
||||
return std::complex<T>((x == 0) ? half_pi : y, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// What follows is the regular Hull et al code,
|
||||
// begin with the special case for real numbers:
|
||||
//
|
||||
if((y == 0) && (x <= one))
|
||||
return std::complex<T>((x == 0) ? half_pi : std::acos(z.real()), (boost::math::changesign)(z.imag()));
|
||||
//
|
||||
// Figure out if our input is within the "safe area" identified by Hull et al.
|
||||
// This would be more efficient with portable floating point exception handling;
|
||||
// fortunately the quantities M and u identified by Hull et al (figure 3),
|
||||
// match with the max and min methods of numeric_limits<T>.
|
||||
//
|
||||
T safe_max = detail::safe_max(static_cast<T>(8));
|
||||
T safe_min = detail::safe_min(static_cast<T>(4));
|
||||
|
||||
T xp1 = one + x;
|
||||
T xm1 = x - one;
|
||||
|
||||
if((x < safe_max) && (x > safe_min) && (y < safe_max) && (y > safe_min))
|
||||
{
|
||||
T yy = y * y;
|
||||
T r = std::sqrt(xp1*xp1 + yy);
|
||||
T s = std::sqrt(xm1*xm1 + yy);
|
||||
T a = half * (r + s);
|
||||
T b = x / a;
|
||||
|
||||
if(b <= b_crossover)
|
||||
{
|
||||
real = std::acos(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
T apx = a + x;
|
||||
if(x <= one)
|
||||
{
|
||||
real = std::atan(std::sqrt(half * apx * (yy /(r + xp1) + (s-xm1)))/x);
|
||||
}
|
||||
else
|
||||
{
|
||||
real = std::atan((y * std::sqrt(half * (apx/(r + xp1) + apx/(s+xm1))))/x);
|
||||
}
|
||||
}
|
||||
|
||||
if(a <= a_crossover)
|
||||
{
|
||||
T am1;
|
||||
if(x < one)
|
||||
{
|
||||
am1 = half * (yy/(r + xp1) + yy/(s - xm1));
|
||||
}
|
||||
else
|
||||
{
|
||||
am1 = half * (yy/(r + xp1) + (s + xm1));
|
||||
}
|
||||
imag = boost::math::log1p(am1 + std::sqrt(am1 * (a + one)));
|
||||
}
|
||||
else
|
||||
{
|
||||
imag = std::log(a + std::sqrt(a*a - one));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// This is the Hull et al exception handling code from Fig 6 of their paper:
|
||||
//
|
||||
if(y <= (std::numeric_limits<T>::epsilon() * std::fabs(xm1)))
|
||||
{
|
||||
if(x < one)
|
||||
{
|
||||
real = std::acos(x);
|
||||
imag = y / std::sqrt(xp1*(one-x));
|
||||
}
|
||||
else
|
||||
{
|
||||
// This deviates from Hull et al's paper as per https://svn.boost.org/trac/boost/ticket/7290
|
||||
if(((std::numeric_limits<T>::max)() / xp1) > xm1)
|
||||
{
|
||||
// xp1 * xm1 won't overflow:
|
||||
real = y / std::sqrt(xm1*xp1);
|
||||
imag = boost::math::log1p(xm1 + std::sqrt(xp1*xm1));
|
||||
}
|
||||
else
|
||||
{
|
||||
real = y / x;
|
||||
imag = log_two + std::log(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(y <= safe_min)
|
||||
{
|
||||
// There is an assumption in Hull et al's analysis that
|
||||
// if we get here then x == 1. This is true for all "good"
|
||||
// machines where :
|
||||
//
|
||||
// E^2 > 8*sqrt(u); with:
|
||||
//
|
||||
// E = std::numeric_limits<T>::epsilon()
|
||||
// u = (std::numeric_limits<T>::min)()
|
||||
//
|
||||
// Hull et al provide alternative code for "bad" machines
|
||||
// but we have no way to test that here, so for now just assert
|
||||
// on the assumption:
|
||||
//
|
||||
BOOST_ASSERT(x == 1);
|
||||
real = std::sqrt(y);
|
||||
imag = std::sqrt(y);
|
||||
}
|
||||
else if(std::numeric_limits<T>::epsilon() * y - one >= x)
|
||||
{
|
||||
real = half_pi;
|
||||
imag = log_two + std::log(y);
|
||||
}
|
||||
else if(x > one)
|
||||
{
|
||||
real = std::atan(y/x);
|
||||
T xoy = x/y;
|
||||
imag = log_two + std::log(y) + half * boost::math::log1p(xoy*xoy);
|
||||
}
|
||||
else
|
||||
{
|
||||
real = half_pi;
|
||||
T a = std::sqrt(one + y*y);
|
||||
imag = half * boost::math::log1p(static_cast<T>(2)*y*(y+a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Finish off by working out the sign of the result:
|
||||
//
|
||||
if((boost::math::signbit)(z.real()))
|
||||
real = s_pi - real;
|
||||
if(!(boost::math::signbit)(z.imag()))
|
||||
imag = (boost::math::changesign)(imag);
|
||||
|
||||
return std::complex<T>(real, imag);
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ACOS_INCLUDED
|
||||
@@ -0,0 +1,34 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_ACOSH_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ACOSH_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED
|
||||
# include <boost/math/complex/acos.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
inline std::complex<T> acosh(const std::complex<T>& z)
|
||||
{
|
||||
//
|
||||
// We use the relation acosh(z) = +-i acos(z)
|
||||
// Choosing the sign of multiplier to give real(acosh(z)) >= 0
|
||||
// as well as compatibility with C99.
|
||||
//
|
||||
std::complex<T> result = boost::math::acos(z);
|
||||
if(!(boost::math::isnan)(result.imag()) && signbit(result.imag()))
|
||||
return detail::mult_i(result);
|
||||
return detail::mult_minus_i(result);
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ACOSH_INCLUDED
|
||||
@@ -0,0 +1,252 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// 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 BOOST_MATH_COMPLEX_ASIN_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ASIN_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_LOG1P_INCLUDED
|
||||
# include <boost/math/special_functions/log1p.hpp>
|
||||
#endif
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; }
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
inline std::complex<T> asin(const std::complex<T>& z)
|
||||
{
|
||||
//
|
||||
// This implementation is a transcription of the pseudo-code in:
|
||||
//
|
||||
// "Implementing the complex Arcsine and Arccosine Functions using Exception Handling."
|
||||
// T E Hull, Thomas F Fairgrieve and Ping Tak Peter Tang.
|
||||
// ACM Transactions on Mathematical Software, Vol 23, No 3, Sept 1997.
|
||||
//
|
||||
|
||||
//
|
||||
// These static constants should really be in a maths constants library,
|
||||
// note that we have tweaked the value of a_crossover as per https://svn.boost.org/trac/boost/ticket/7290:
|
||||
//
|
||||
static const T one = static_cast<T>(1);
|
||||
//static const T two = static_cast<T>(2);
|
||||
static const T half = static_cast<T>(0.5L);
|
||||
static const T a_crossover = static_cast<T>(10);
|
||||
static const T b_crossover = static_cast<T>(0.6417L);
|
||||
static const T s_pi = boost::math::constants::pi<T>();
|
||||
static const T half_pi = s_pi / 2;
|
||||
static const T log_two = boost::math::constants::ln_two<T>();
|
||||
static const T quarter_pi = s_pi / 4;
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127)
|
||||
#endif
|
||||
//
|
||||
// Get real and imaginary parts, discard the signs as we can
|
||||
// figure out the sign of the result later:
|
||||
//
|
||||
T x = std::fabs(z.real());
|
||||
T y = std::fabs(z.imag());
|
||||
T real, imag; // our results
|
||||
|
||||
//
|
||||
// Begin by handling the special cases for infinities and nan's
|
||||
// specified in C99, most of this is handled by the regular logic
|
||||
// below, but handling it as a special case prevents overflow/underflow
|
||||
// arithmetic which may trip up some machines:
|
||||
//
|
||||
if((boost::math::isnan)(x))
|
||||
{
|
||||
if((boost::math::isnan)(y))
|
||||
return std::complex<T>(x, x);
|
||||
if((boost::math::isinf)(y))
|
||||
{
|
||||
real = x;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else
|
||||
return std::complex<T>(x, x);
|
||||
}
|
||||
else if((boost::math::isnan)(y))
|
||||
{
|
||||
if(x == 0)
|
||||
{
|
||||
real = 0;
|
||||
imag = y;
|
||||
}
|
||||
else if((boost::math::isinf)(x))
|
||||
{
|
||||
real = y;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else
|
||||
return std::complex<T>(y, y);
|
||||
}
|
||||
else if((boost::math::isinf)(x))
|
||||
{
|
||||
if((boost::math::isinf)(y))
|
||||
{
|
||||
real = quarter_pi;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else
|
||||
{
|
||||
real = half_pi;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
}
|
||||
else if((boost::math::isinf)(y))
|
||||
{
|
||||
real = 0;
|
||||
imag = std::numeric_limits<T>::infinity();
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// special case for real numbers:
|
||||
//
|
||||
if((y == 0) && (x <= one))
|
||||
return std::complex<T>(std::asin(z.real()), z.imag());
|
||||
//
|
||||
// Figure out if our input is within the "safe area" identified by Hull et al.
|
||||
// This would be more efficient with portable floating point exception handling;
|
||||
// fortunately the quantities M and u identified by Hull et al (figure 3),
|
||||
// match with the max and min methods of numeric_limits<T>.
|
||||
//
|
||||
T safe_max = detail::safe_max(static_cast<T>(8));
|
||||
T safe_min = detail::safe_min(static_cast<T>(4));
|
||||
|
||||
T xp1 = one + x;
|
||||
T xm1 = x - one;
|
||||
|
||||
if((x < safe_max) && (x > safe_min) && (y < safe_max) && (y > safe_min))
|
||||
{
|
||||
T yy = y * y;
|
||||
T r = std::sqrt(xp1*xp1 + yy);
|
||||
T s = std::sqrt(xm1*xm1 + yy);
|
||||
T a = half * (r + s);
|
||||
T b = x / a;
|
||||
|
||||
if(b <= b_crossover)
|
||||
{
|
||||
real = std::asin(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
T apx = a + x;
|
||||
if(x <= one)
|
||||
{
|
||||
real = std::atan(x/std::sqrt(half * apx * (yy /(r + xp1) + (s-xm1))));
|
||||
}
|
||||
else
|
||||
{
|
||||
real = std::atan(x/(y * std::sqrt(half * (apx/(r + xp1) + apx/(s+xm1)))));
|
||||
}
|
||||
}
|
||||
|
||||
if(a <= a_crossover)
|
||||
{
|
||||
T am1;
|
||||
if(x < one)
|
||||
{
|
||||
am1 = half * (yy/(r + xp1) + yy/(s - xm1));
|
||||
}
|
||||
else
|
||||
{
|
||||
am1 = half * (yy/(r + xp1) + (s + xm1));
|
||||
}
|
||||
imag = boost::math::log1p(am1 + std::sqrt(am1 * (a + one)));
|
||||
}
|
||||
else
|
||||
{
|
||||
imag = std::log(a + std::sqrt(a*a - one));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// This is the Hull et al exception handling code from Fig 3 of their paper:
|
||||
//
|
||||
if(y <= (std::numeric_limits<T>::epsilon() * std::fabs(xm1)))
|
||||
{
|
||||
if(x < one)
|
||||
{
|
||||
real = std::asin(x);
|
||||
imag = y / std::sqrt(-xp1*xm1);
|
||||
}
|
||||
else
|
||||
{
|
||||
real = half_pi;
|
||||
if(((std::numeric_limits<T>::max)() / xp1) > xm1)
|
||||
{
|
||||
// xp1 * xm1 won't overflow:
|
||||
imag = boost::math::log1p(xm1 + std::sqrt(xp1*xm1));
|
||||
}
|
||||
else
|
||||
{
|
||||
imag = log_two + std::log(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(y <= safe_min)
|
||||
{
|
||||
// There is an assumption in Hull et al's analysis that
|
||||
// if we get here then x == 1. This is true for all "good"
|
||||
// machines where :
|
||||
//
|
||||
// E^2 > 8*sqrt(u); with:
|
||||
//
|
||||
// E = std::numeric_limits<T>::epsilon()
|
||||
// u = (std::numeric_limits<T>::min)()
|
||||
//
|
||||
// Hull et al provide alternative code for "bad" machines
|
||||
// but we have no way to test that here, so for now just assert
|
||||
// on the assumption:
|
||||
//
|
||||
BOOST_ASSERT(x == 1);
|
||||
real = half_pi - std::sqrt(y);
|
||||
imag = std::sqrt(y);
|
||||
}
|
||||
else if(std::numeric_limits<T>::epsilon() * y - one >= x)
|
||||
{
|
||||
real = x/y; // This can underflow!
|
||||
imag = log_two + std::log(y);
|
||||
}
|
||||
else if(x > one)
|
||||
{
|
||||
real = std::atan(x/y);
|
||||
T xoy = x/y;
|
||||
imag = log_two + std::log(y) + half * boost::math::log1p(xoy*xoy);
|
||||
}
|
||||
else
|
||||
{
|
||||
T a = std::sqrt(one + y*y);
|
||||
real = x/a; // This can underflow!
|
||||
imag = half * boost::math::log1p(static_cast<T>(2)*y*(y+a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Finish off by working out the sign of the result:
|
||||
//
|
||||
if((boost::math::signbit)(z.real()))
|
||||
real = (boost::math::changesign)(real);
|
||||
if((boost::math::signbit)(z.imag()))
|
||||
imag = (boost::math::changesign)(imag);
|
||||
|
||||
return std::complex<T>(real, imag);
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ASIN_INCLUDED
|
||||
@@ -0,0 +1,32 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_ASINH_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ASINH_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_COMPLEX_ASIN_INCLUDED
|
||||
# include <boost/math/complex/asin.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
inline std::complex<T> asinh(const std::complex<T>& x)
|
||||
{
|
||||
//
|
||||
// We use asinh(z) = i asin(-i z);
|
||||
// Note that C99 defines this the other way around (which is
|
||||
// to say asin is specified in terms of asinh), this is consistent
|
||||
// with C99 though:
|
||||
//
|
||||
return ::boost::math::detail::mult_i(::boost::math::asin(::boost::math::detail::mult_minus_i(x)));
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ASINH_INCLUDED
|
||||
@@ -0,0 +1,36 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_ATAN_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ATAN_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_COMPLEX_ATANH_INCLUDED
|
||||
# include <boost/math/complex/atanh.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
std::complex<T> atan(const std::complex<T>& x)
|
||||
{
|
||||
//
|
||||
// We're using the C99 definition here; atan(z) = -i atanh(iz):
|
||||
//
|
||||
if(x.real() == 0)
|
||||
{
|
||||
if(x.imag() == 1)
|
||||
return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : static_cast<T>(HUGE_VAL));
|
||||
if(x.imag() == -1)
|
||||
return std::complex<T>(0, std::numeric_limits<T>::has_infinity ? -std::numeric_limits<T>::infinity() : -static_cast<T>(HUGE_VAL));
|
||||
}
|
||||
return ::boost::math::detail::mult_minus_i(::boost::math::atanh(::boost::math::detail::mult_i(x)));
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ATAN_INCLUDED
|
||||
@@ -0,0 +1,214 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_ATANH_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_ATANH_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
# include <boost/math/complex/details.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_MATH_LOG1P_INCLUDED
|
||||
# include <boost/math/special_functions/log1p.hpp>
|
||||
#endif
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std{ using ::sqrt; using ::fabs; using ::acos; using ::asin; using ::atan; using ::atan2; }
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
std::complex<T> atanh(const std::complex<T>& z)
|
||||
{
|
||||
//
|
||||
// References:
|
||||
//
|
||||
// Eric W. Weisstein. "Inverse Hyperbolic Tangent."
|
||||
// From MathWorld--A Wolfram Web Resource.
|
||||
// http://mathworld.wolfram.com/InverseHyperbolicTangent.html
|
||||
//
|
||||
// Also: The Wolfram Functions Site,
|
||||
// http://functions.wolfram.com/ElementaryFunctions/ArcTanh/
|
||||
//
|
||||
// Also "Abramowitz and Stegun. Handbook of Mathematical Functions."
|
||||
// at : http://jove.prohosting.com/~skripty/toc.htm
|
||||
//
|
||||
// See also: https://svn.boost.org/trac/boost/ticket/7291
|
||||
//
|
||||
|
||||
static const T pi = boost::math::constants::pi<T>();
|
||||
static const T half_pi = pi / 2;
|
||||
static const T one = static_cast<T>(1.0L);
|
||||
static const T two = static_cast<T>(2.0L);
|
||||
static const T four = static_cast<T>(4.0L);
|
||||
static const T zero = static_cast<T>(0);
|
||||
static const T log_two = boost::math::constants::ln_two<T>();
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127)
|
||||
#endif
|
||||
|
||||
T x = std::fabs(z.real());
|
||||
T y = std::fabs(z.imag());
|
||||
|
||||
T real, imag; // our results
|
||||
|
||||
T safe_upper = detail::safe_max(two);
|
||||
T safe_lower = detail::safe_min(static_cast<T>(2));
|
||||
|
||||
//
|
||||
// Begin by handling the special cases specified in C99:
|
||||
//
|
||||
if((boost::math::isnan)(x))
|
||||
{
|
||||
if((boost::math::isnan)(y))
|
||||
return std::complex<T>(x, x);
|
||||
else if((boost::math::isinf)(y))
|
||||
return std::complex<T>(0, ((boost::math::signbit)(z.imag()) ? -half_pi : half_pi));
|
||||
else
|
||||
return std::complex<T>(x, x);
|
||||
}
|
||||
else if((boost::math::isnan)(y))
|
||||
{
|
||||
if(x == 0)
|
||||
return std::complex<T>(x, y);
|
||||
if((boost::math::isinf)(x))
|
||||
return std::complex<T>(0, y);
|
||||
else
|
||||
return std::complex<T>(y, y);
|
||||
}
|
||||
else if((x > safe_lower) && (x < safe_upper) && (y > safe_lower) && (y < safe_upper))
|
||||
{
|
||||
|
||||
T yy = y*y;
|
||||
T mxm1 = one - x;
|
||||
///
|
||||
// The real part is given by:
|
||||
//
|
||||
// real(atanh(z)) == log1p(4*x / ((x-1)*(x-1) + y^2))
|
||||
//
|
||||
real = boost::math::log1p(four * x / (mxm1*mxm1 + yy));
|
||||
real /= four;
|
||||
if((boost::math::signbit)(z.real()))
|
||||
real = (boost::math::changesign)(real);
|
||||
|
||||
imag = std::atan2((y * two), (mxm1*(one+x) - yy));
|
||||
imag /= two;
|
||||
if(z.imag() < 0)
|
||||
imag = (boost::math::changesign)(imag);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// This section handles exception cases that would normally cause
|
||||
// underflow or overflow in the main formulas.
|
||||
//
|
||||
// Begin by working out the real part, we need to approximate
|
||||
// real = boost::math::log1p(4x / ((x-1)^2 + y^2))
|
||||
// without either overflow or underflow in the squared terms.
|
||||
//
|
||||
T mxm1 = one - x;
|
||||
if(x >= safe_upper)
|
||||
{
|
||||
// x-1 = x to machine precision:
|
||||
if((boost::math::isinf)(x) || (boost::math::isinf)(y))
|
||||
{
|
||||
real = 0;
|
||||
}
|
||||
else if(y >= safe_upper)
|
||||
{
|
||||
// Big x and y: divide through by x*y:
|
||||
real = boost::math::log1p((four/y) / (x/y + y/x));
|
||||
}
|
||||
else if(y > one)
|
||||
{
|
||||
// Big x: divide through by x:
|
||||
real = boost::math::log1p(four / (x + y*y/x));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Big x small y, as above but neglect y^2/x:
|
||||
real = boost::math::log1p(four/x);
|
||||
}
|
||||
}
|
||||
else if(y >= safe_upper)
|
||||
{
|
||||
if(x > one)
|
||||
{
|
||||
// Big y, medium x, divide through by y:
|
||||
real = boost::math::log1p((four*x/y) / (y + mxm1*mxm1/y));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Small or medium x, large y:
|
||||
real = four*x/y/y;
|
||||
}
|
||||
}
|
||||
else if (x != one)
|
||||
{
|
||||
// y is small, calculate divisor carefully:
|
||||
T div = mxm1*mxm1;
|
||||
if(y > safe_lower)
|
||||
div += y*y;
|
||||
real = boost::math::log1p(four*x/div);
|
||||
}
|
||||
else
|
||||
real = boost::math::changesign(two * (std::log(y) - log_two));
|
||||
|
||||
real /= four;
|
||||
if((boost::math::signbit)(z.real()))
|
||||
real = (boost::math::changesign)(real);
|
||||
|
||||
//
|
||||
// Now handle imaginary part, this is much easier,
|
||||
// if x or y are large, then the formula:
|
||||
// atan2(2y, (1-x)*(1+x) - y^2)
|
||||
// evaluates to +-(PI - theta) where theta is negligible compared to PI.
|
||||
//
|
||||
if((x >= safe_upper) || (y >= safe_upper))
|
||||
{
|
||||
imag = pi;
|
||||
}
|
||||
else if(x <= safe_lower)
|
||||
{
|
||||
//
|
||||
// If both x and y are small then atan(2y),
|
||||
// otherwise just x^2 is negligible in the divisor:
|
||||
//
|
||||
if(y <= safe_lower)
|
||||
imag = std::atan2(two*y, one);
|
||||
else
|
||||
{
|
||||
if((y == zero) && (x == zero))
|
||||
imag = 0;
|
||||
else
|
||||
imag = std::atan2(two*y, one - y*y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// y^2 is negligible:
|
||||
//
|
||||
if((y == zero) && (x == one))
|
||||
imag = 0;
|
||||
else
|
||||
imag = std::atan2(two*y, mxm1*(one+x));
|
||||
}
|
||||
imag /= two;
|
||||
if((boost::math::signbit)(z.imag()))
|
||||
imag = (boost::math::changesign)(imag);
|
||||
}
|
||||
return std::complex<T>(real, imag);
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_ATANH_INCLUDED
|
||||
@@ -0,0 +1,96 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
//
|
||||
// This header contains all the support code that is common to the
|
||||
// inverse trig complex functions, it also contains all the includes
|
||||
// that we need to implement all these functions.
|
||||
//
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/config/no_tr1/complex.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
#include <math.h> // isnan where available
|
||||
#include <boost/config/no_tr1/cmath.hpp>
|
||||
#include <boost/math/special_functions/sign.hpp>
|
||||
#include <boost/math/special_functions/fpclassify.hpp>
|
||||
#include <boost/math/special_functions/sign.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std{ using ::sqrt; }
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{ namespace detail{
|
||||
|
||||
template <class T>
|
||||
inline T mult_minus_one(const T& t)
|
||||
{
|
||||
return (boost::math::isnan)(t) ? t : (boost::math::changesign)(t);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline std::complex<T> mult_i(const std::complex<T>& t)
|
||||
{
|
||||
return std::complex<T>(mult_minus_one(t.imag()), t.real());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline std::complex<T> mult_minus_i(const std::complex<T>& t)
|
||||
{
|
||||
return std::complex<T>(t.imag(), mult_minus_one(t.real()));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T safe_max(T t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<T>::max)()) / t;
|
||||
}
|
||||
inline long double safe_max(long double t)
|
||||
{
|
||||
// long double sqrt often returns infinity due to
|
||||
// insufficient internal precision:
|
||||
return std::sqrt((std::numeric_limits<double>::max)()) / t;
|
||||
}
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
// workaround for type deduction bug:
|
||||
inline float safe_max(float t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<float>::max)()) / t;
|
||||
}
|
||||
inline double safe_max(double t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<double>::max)()) / t;
|
||||
}
|
||||
#endif
|
||||
template <class T>
|
||||
inline T safe_min(T t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<T>::min)()) * t;
|
||||
}
|
||||
inline long double safe_min(long double t)
|
||||
{
|
||||
// long double sqrt often returns zero due to
|
||||
// insufficient internal precision:
|
||||
return std::sqrt((std::numeric_limits<double>::min)()) * t;
|
||||
}
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
// type deduction workaround:
|
||||
inline double safe_min(double t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<double>::min)()) * t;
|
||||
}
|
||||
inline float safe_min(float t)
|
||||
{
|
||||
return std::sqrt((std::numeric_limits<float>::min)()) * t;
|
||||
}
|
||||
#endif
|
||||
|
||||
} } } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to 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 BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_HYPOT_INCLUDED
|
||||
# include <boost/math/special_functions/hypot.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
inline T fabs(const std::complex<T>& z)
|
||||
{
|
||||
return ::boost::math::hypot(z.real(), z.imag());
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
Reference in New Issue
Block a user