1 // (C) Copyright John Maddock 2005. 2 // Use, modification and distribution are subject to the 3 // Boost Software License, Version 1.0. (See accompanying file 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED 7 #define BOOST_MATH_COMPLEX_DETAILS_INCLUDED 8 // 9 // This header contains all the support code that is common to the 10 // inverse trig complex functions, it also contains all the includes 11 // that we need to implement all these functions. 12 // 13 #include <boost/config.hpp> 14 #include <boost/detail/workaround.hpp> 15 #include <boost/config/no_tr1/complex.hpp> 16 #include <boost/limits.hpp> 17 #include <math.h> // isnan where available 18 #include <boost/config/no_tr1/cmath.hpp> 19 #include <boost/math/special_functions/sign.hpp> 20 #include <boost/math/special_functions/fpclassify.hpp> 21 #include <boost/math/special_functions/sign.hpp> 22 #include <boost/math/constants/constants.hpp> 23 24 #ifdef BOOST_NO_STDC_NAMESPACE 25 namespace std{ using ::sqrt; } 26 #endif 27 28 namespace boost{ namespace math{ namespace detail{ 29 30 template <class T> mult_minus_one(const T & t)31inline T mult_minus_one(const T& t) 32 { 33 return (boost::math::isnan)(t) ? t : (boost::math::changesign)(t); 34 } 35 36 template <class T> mult_i(const std::complex<T> & t)37inline std::complex<T> mult_i(const std::complex<T>& t) 38 { 39 return std::complex<T>(mult_minus_one(t.imag()), t.real()); 40 } 41 42 template <class T> mult_minus_i(const std::complex<T> & t)43inline std::complex<T> mult_minus_i(const std::complex<T>& t) 44 { 45 return std::complex<T>(t.imag(), mult_minus_one(t.real())); 46 } 47 48 template <class T> safe_max(T t)49inline T safe_max(T t) 50 { 51 return std::sqrt((std::numeric_limits<T>::max)()) / t; 52 } safe_max(long double t)53inline long double safe_max(long double t) 54 { 55 // long double sqrt often returns infinity due to 56 // insufficient internal precision: 57 return std::sqrt((std::numeric_limits<double>::max)()) / t; 58 } 59 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) 60 // workaround for type deduction bug: safe_max(float t)61inline float safe_max(float t) 62 { 63 return std::sqrt((std::numeric_limits<float>::max)()) / t; 64 } safe_max(double t)65inline double safe_max(double t) 66 { 67 return std::sqrt((std::numeric_limits<double>::max)()) / t; 68 } 69 #endif 70 template <class T> safe_min(T t)71inline T safe_min(T t) 72 { 73 return std::sqrt((std::numeric_limits<T>::min)()) * t; 74 } safe_min(long double t)75inline long double safe_min(long double t) 76 { 77 // long double sqrt often returns zero due to 78 // insufficient internal precision: 79 return std::sqrt((std::numeric_limits<double>::min)()) * t; 80 } 81 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) 82 // type deduction workaround: safe_min(double t)83inline double safe_min(double t) 84 { 85 return std::sqrt((std::numeric_limits<double>::min)()) * t; 86 } safe_min(float t)87inline float safe_min(float t) 88 { 89 return std::sqrt((std::numeric_limits<float>::min)()) * t; 90 } 91 #endif 92 93 } } } // namespaces 94 95 #endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED 96 97