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