details.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <cmath>
  13. #include <complex>
  14. #include <limits>
  15. #include <boost/math/special_functions/sign.hpp>
  16. #include <boost/math/special_functions/fpclassify.hpp>
  17. #include <boost/math/constants/constants.hpp>
  18. namespace boost{ namespace math{ namespace detail{
  19. template <class T>
  20. inline T mult_minus_one(const T& t)
  21. {
  22. return (boost::math::isnan)(t) ? t : (boost::math::changesign)(t);
  23. }
  24. template <class T>
  25. inline std::complex<T> mult_i(const std::complex<T>& t)
  26. {
  27. return std::complex<T>(mult_minus_one(t.imag()), t.real());
  28. }
  29. template <class T>
  30. inline std::complex<T> mult_minus_i(const std::complex<T>& t)
  31. {
  32. return std::complex<T>(t.imag(), mult_minus_one(t.real()));
  33. }
  34. template <class T>
  35. inline T safe_max(T t)
  36. {
  37. return std::sqrt((std::numeric_limits<T>::max)()) / t;
  38. }
  39. inline long double safe_max(long double t)
  40. {
  41. // long double sqrt often returns infinity due to
  42. // insufficient internal precision:
  43. return std::sqrt((std::numeric_limits<double>::max)()) / t;
  44. }
  45. template <class T>
  46. inline T safe_min(T t)
  47. {
  48. return std::sqrt((std::numeric_limits<T>::min)()) * t;
  49. }
  50. inline long double safe_min(long double t)
  51. {
  52. // long double sqrt often returns zero due to
  53. // insufficient internal precision:
  54. return std::sqrt((std::numeric_limits<double>::min)()) * t;
  55. }
  56. } } } // namespaces
  57. #endif // BOOST_MATH_COMPLEX_DETAILS_INCLUDED