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