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