details.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef BOOST_MATH_COMPLEX_DETAILS_INCLUDED
  6. #define BOOST_MATH_COMPLEX_DETAILS_INCLUDED
  7. //
  8. // This header contains all the support code that is common to the
  9. // inverse trig complex functions, it also contains all the includes
  10. // that we need to implement all these functions.
  11. //
  12. #include <boost/config.hpp>
  13. #include <boost/detail/workaround.hpp>
  14. #include <boost/config/no_tr1/complex.hpp>
  15. #include <boost/limits.hpp>
  16. #include <math.h> // isnan where available
  17. #include <boost/config/no_tr1/cmath.hpp>
  18. #include <boost/math/special_functions/sign.hpp>
  19. #include <boost/math/special_functions/fpclassify.hpp>
  20. #include <boost/math/special_functions/sign.hpp>
  21. #include <boost/math/constants/constants.hpp>
  22. #ifdef BOOST_NO_STDC_NAMESPACE
  23. namespace std{ using ::sqrt; }
  24. #endif
  25. namespace boost{ namespace math{ namespace detail{
  26. template <class T>
  27. inline T mult_minus_one(const T& t)
  28. {
  29. return (boost::math::isnan)(t) ? t : (boost::math::changesign)(t);
  30. }
  31. template <class T>
  32. inline std::complex<T> mult_i(const std::complex<T>& t)
  33. {
  34. return std::complex<T>(mult_minus_one(t.imag()), t.real());
  35. }
  36. template <class T>
  37. inline std::complex<T> mult_minus_i(const std::complex<T>& t)
  38. {
  39. return std::complex<T>(t.imag(), mult_minus_one(t.real()));
  40. }
  41. template <class T>
  42. inline T safe_max(T t)
  43. {
  44. return std::sqrt((std::numeric_limits<T>::max)()) / t;
  45. }
  46. inline long double safe_max(long double t)
  47. {
  48. // long double sqrt often returns infinity due to
  49. // insufficient internal precision:
  50. return std::sqrt((std::numeric_limits<double>::max)()) / t;
  51. }
  52. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  53. // workaround for type deduction bug:
  54. inline float safe_max(float t)
  55. {
  56. return std::sqrt((std::numeric_limits<float>::max)()) / t;
  57. }
  58. inline double safe_max(double t)
  59. {
  60. return std::sqrt((std::numeric_limits<double>::max)()) / t;
  61. }
  62. #endif
  63. template <class T>
  64. inline T safe_min(T t)
  65. {
  66. return std::sqrt((std::numeric_limits<T>::min)()) * t;
  67. }
  68. inline long double safe_min(long double t)
  69. {
  70. // long double sqrt often returns zero due to
  71. // insufficient internal precision:
  72. return std::sqrt((std::numeric_limits<double>::min)()) * t;
  73. }
  74. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  75. // type deduction workaround:
  76. inline double safe_min(double t)
  77. {
  78. return std::sqrt((std::numeric_limits<double>::min)()) * t;
  79. }
  80. inline float safe_min(float t)
  81. {
  82. return std::sqrt((std::numeric_limits<float>::min)()) * t;
  83. }
  84. #endif
  85. } } } // namespaces
  86. #endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED