williamr@2: // (C) Copyright John Maddock 2005. williamr@2: // Use, modification and distribution are subject to the williamr@2: // Boost Software License, Version 1.0. (See accompanying file williamr@2: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) williamr@2: williamr@2: #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED williamr@2: #define BOOST_MATH_COMPLEX_DETAILS_INCLUDED williamr@2: // williamr@2: // This header contains all the support code that is common to the williamr@2: // inverse trig complex functions, it also contains all the includes williamr@2: // that we need to implement all these functions. williamr@2: // williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include // isnan where available williamr@2: #include williamr@2: williamr@2: #ifdef BOOST_NO_STDC_NAMESPACE williamr@2: namespace std{ using ::sqrt; } williamr@2: #endif williamr@2: williamr@2: namespace boost{ namespace math{ namespace detail{ williamr@2: williamr@2: template williamr@2: inline bool test_is_nan(T t) williamr@2: { williamr@2: // Comparisons with Nan's always fail: williamr@2: return std::numeric_limits::has_infinity && (!(t <= std::numeric_limits::infinity()) || !(t >= -std::numeric_limits::infinity())); williamr@2: } williamr@2: #ifdef isnan williamr@2: template<> inline bool test_is_nan(float t) { return isnan(t); } williamr@2: template<> inline bool test_is_nan(double t) { return isnan(t); } williamr@2: template<> inline bool test_is_nan(long double t) { return isnan(t); } williamr@2: #endif williamr@2: williamr@2: template williamr@2: inline T mult_minus_one(const T& t) williamr@2: { williamr@2: return test_is_nan(t) ? t : -t; williamr@2: } williamr@2: williamr@2: template williamr@2: inline std::complex mult_i(const std::complex& t) williamr@2: { williamr@2: return std::complex(mult_minus_one(t.imag()), t.real()); williamr@2: } williamr@2: williamr@2: template williamr@2: inline std::complex mult_minus_i(const std::complex& t) williamr@2: { williamr@2: return std::complex(t.imag(), mult_minus_one(t.real())); williamr@2: } williamr@2: williamr@2: template williamr@2: inline T safe_max(T t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::max)()) / t; williamr@2: } williamr@2: inline long double safe_max(long double t) williamr@2: { williamr@2: // long double sqrt often returns infinity due to williamr@2: // insufficient internal precision: williamr@2: return std::sqrt((std::numeric_limits::max)()) / t; williamr@2: } williamr@2: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) williamr@2: // workaround for type deduction bug: williamr@2: inline float safe_max(float t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::max)()) / t; williamr@2: } williamr@2: inline double safe_max(double t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::max)()) / t; williamr@2: } williamr@2: #endif williamr@2: template williamr@2: inline T safe_min(T t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::min)()) * t; williamr@2: } williamr@2: inline long double safe_min(long double t) williamr@2: { williamr@2: // long double sqrt often returns zero due to williamr@2: // insufficient internal precision: williamr@2: return std::sqrt((std::numeric_limits::min)()) * t; williamr@2: } williamr@2: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) williamr@2: // type deduction workaround: williamr@2: inline double safe_min(double t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::min)()) * t; williamr@2: } williamr@2: inline float safe_min(float t) williamr@2: { williamr@2: return std::sqrt((std::numeric_limits::min)()) * t; williamr@2: } williamr@2: #endif williamr@2: williamr@2: } } } // namespaces williamr@2: williamr@2: #endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED williamr@2: