special_function_util.h

Go to the documentation of this file.
00001 // Special functions -*- C++ -*-
00002 
00003 // Copyright (C) 2006
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 /** @file tr1/special_function_util.h
00032  *  This is an internal header file, included by other library headers.
00033  *  You should not attempt to use it directly.
00034  */
00035 
00036 //
00037 // ISO C++ 14882 TR1: 5.2  Special functions
00038 //
00039 
00040 // Written by Edward Smith-Rowland based on numerous mathematics books.
00041 
00042 #ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H
00043 #define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1
00044 
00045 namespace std
00046 {
00047 namespace tr1
00048 {
00049 
00050   namespace __detail
00051   {
00052 
00053     /// A class to encapsulate type dependent floating point
00054     /// constants.  Not everything will be able to be expressed as
00055     /// type logic.
00056     template<typename _Tp>
00057     struct __floating_point_constant
00058     {
00059       static const _Tp __value;
00060     };
00061 
00062 
00063     /// A structure for numeric constants.
00064     template<typename _Tp>
00065       struct __numeric_constants
00066       {
00067         ///  Constant @f$ \pi @f$.
00068         static _Tp __pi() throw()
00069         { return static_cast<_Tp>(3.1415926535897932384626433832795029L); }
00070         ///  Constant @f$ \pi / 2 @f$.
00071         static _Tp __pi_2() throw()
00072         { return static_cast<_Tp>(1.5707963267948966192313216916397514L); }
00073         ///  Constant @f$ \pi / 3 @f$.
00074         static _Tp __pi_3() throw()
00075         { return static_cast<_Tp>(1.0471975511965977461542144610931676L); }
00076         ///  Constant @f$ \pi / 4 @f$.
00077         static _Tp __pi_4() throw()
00078         { return static_cast<_Tp>(0.7853981633974483096156608458198757L); }
00079         ///  Constant @f$ 1 / \pi @f$.
00080         static _Tp __1_pi() throw()
00081         { return static_cast<_Tp>(0.3183098861837906715377675267450287L); }
00082         ///  Constant @f$ 2 / \sqrt(\pi) @f$.
00083         static _Tp __2_sqrtpi() throw()
00084         { return static_cast<_Tp>(1.1283791670955125738961589031215452L); }
00085         ///  Constant @f$ \sqrt(2) @f$.
00086         static _Tp __sqrt2() throw()
00087         { return static_cast<_Tp>(1.4142135623730950488016887242096981L); }
00088         ///  Constant @f$ \sqrt(3) @f$.
00089         static _Tp __sqrt3() throw()
00090         { return static_cast<_Tp>(1.7320508075688772935274463415058723L); }
00091         ///  Constant @f$ \sqrt(\pi/2) @f$.
00092         static _Tp __sqrtpio2() throw()
00093         { return static_cast<_Tp>(1.2533141373155002512078826424055226L); }
00094         ///  Constant @f$ 1 / sqrt(2) @f$.
00095         static _Tp __sqrt1_2() throw()
00096         { return static_cast<_Tp>(0.7071067811865475244008443621048490L); }
00097         ///  Constant @f$ \log(\pi) @f$.
00098         static _Tp __lnpi() throw()
00099         { return static_cast<_Tp>(1.1447298858494001741434273513530587L); }
00100         ///  Constant Euler's constant @f$ \gamma_E @f$.
00101         static _Tp __gamma_e() throw()
00102         { return static_cast<_Tp>(0.5772156649015328606065120900824024L); }
00103         ///  Constant Euler-Mascheroni @f$ e @f$
00104         static _Tp __euler() throw()
00105         { return static_cast<_Tp>(2.7182818284590452353602874713526625L); }
00106       };
00107 
00108 
00109 #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
00110 
00111     /// This is a wrapper for the isnan function. Otherwise, for NaN,
00112     /// all comparisons result in false. If/when we build a std::isnan
00113     /// out of intrinsics, this will disappear completely in favor of
00114     /// std::isnan.
00115     template<typename _Tp>
00116     inline bool __isnan(const _Tp __x)
00117     {
00118       return std::isnan(__x);
00119     }
00120 
00121 #else
00122 
00123     template<typename _Tp>
00124     inline bool __isnan(const _Tp __x)
00125     {
00126       return __builtin_isnan(__x);
00127     }
00128 
00129     template<>
00130     inline bool __isnan<float>(const float __x)
00131     {
00132       return __builtin_isnanf(__x);
00133     }
00134 
00135     template<>
00136     inline bool __isnan<long double>(const long double __x)
00137     {
00138       return __builtin_isnanl(__x);
00139     }
00140 
00141 #endif
00142 
00143   } // namespace __detail
00144 
00145 }
00146 }
00147 
00148 #endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H
00149 

Generated on Wed Dec 31 12:49:00 2008 for libstdc++ by  doxygen 1.5.6