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