libstdc++
|
00001 // Special functions -*- C++ -*- 00002 00003 // Copyright (C) 2006, 2009 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /** @file tr1/special_function_util.h 00027 * This is an internal header file, included by other library headers. 00028 * You should not attempt to use it directly. 00029 */ 00030 00031 // 00032 // ISO C++ 14882 TR1: 5.2 Special functions 00033 // 00034 00035 // Written by Edward Smith-Rowland based on numerous mathematics books. 00036 00037 #ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 00038 #define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1 00039 00040 namespace std 00041 { 00042 namespace tr1 00043 { 00044 00045 namespace __detail 00046 { 00047 00048 /// A class to encapsulate type dependent floating point 00049 /// constants. Not everything will be able to be expressed as 00050 /// type logic. 00051 template<typename _Tp> 00052 struct __floating_point_constant 00053 { 00054 static const _Tp __value; 00055 }; 00056 00057 00058 /// A structure for numeric constants. 00059 template<typename _Tp> 00060 struct __numeric_constants 00061 { 00062 /// Constant @f$ \pi @f$. 00063 static _Tp __pi() throw() 00064 { return static_cast<_Tp>(3.1415926535897932384626433832795029L); } 00065 /// Constant @f$ \pi / 2 @f$. 00066 static _Tp __pi_2() throw() 00067 { return static_cast<_Tp>(1.5707963267948966192313216916397514L); } 00068 /// Constant @f$ \pi / 3 @f$. 00069 static _Tp __pi_3() throw() 00070 { return static_cast<_Tp>(1.0471975511965977461542144610931676L); } 00071 /// Constant @f$ \pi / 4 @f$. 00072 static _Tp __pi_4() throw() 00073 { return static_cast<_Tp>(0.7853981633974483096156608458198757L); } 00074 /// Constant @f$ 1 / \pi @f$. 00075 static _Tp __1_pi() throw() 00076 { return static_cast<_Tp>(0.3183098861837906715377675267450287L); } 00077 /// Constant @f$ 2 / \sqrt(\pi) @f$. 00078 static _Tp __2_sqrtpi() throw() 00079 { return static_cast<_Tp>(1.1283791670955125738961589031215452L); } 00080 /// Constant @f$ \sqrt(2) @f$. 00081 static _Tp __sqrt2() throw() 00082 { return static_cast<_Tp>(1.4142135623730950488016887242096981L); } 00083 /// Constant @f$ \sqrt(3) @f$. 00084 static _Tp __sqrt3() throw() 00085 { return static_cast<_Tp>(1.7320508075688772935274463415058723L); } 00086 /// Constant @f$ \sqrt(\pi/2) @f$. 00087 static _Tp __sqrtpio2() throw() 00088 { return static_cast<_Tp>(1.2533141373155002512078826424055226L); } 00089 /// Constant @f$ 1 / sqrt(2) @f$. 00090 static _Tp __sqrt1_2() throw() 00091 { return static_cast<_Tp>(0.7071067811865475244008443621048490L); } 00092 /// Constant @f$ \log(\pi) @f$. 00093 static _Tp __lnpi() throw() 00094 { return static_cast<_Tp>(1.1447298858494001741434273513530587L); } 00095 /// Constant Euler's constant @f$ \gamma_E @f$. 00096 static _Tp __gamma_e() throw() 00097 { return static_cast<_Tp>(0.5772156649015328606065120900824024L); } 00098 /// Constant Euler-Mascheroni @f$ e @f$ 00099 static _Tp __euler() throw() 00100 { return static_cast<_Tp>(2.7182818284590452353602874713526625L); } 00101 }; 00102 00103 00104 #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 00105 00106 /// This is a wrapper for the isnan function. Otherwise, for NaN, 00107 /// all comparisons result in false. If/when we build a std::isnan 00108 /// out of intrinsics, this will disappear completely in favor of 00109 /// std::isnan. 00110 template<typename _Tp> 00111 inline bool __isnan(const _Tp __x) 00112 { 00113 return std::isnan(__x); 00114 } 00115 00116 #else 00117 00118 template<typename _Tp> 00119 inline bool __isnan(const _Tp __x) 00120 { 00121 return __builtin_isnan(__x); 00122 } 00123 00124 template<> 00125 inline bool __isnan<float>(const float __x) 00126 { 00127 return __builtin_isnanf(__x); 00128 } 00129 00130 template<> 00131 inline bool __isnan<long double>(const long double __x) 00132 { 00133 return __builtin_isnanl(__x); 00134 } 00135 00136 #endif 00137 00138 } // namespace __detail 00139 00140 } 00141 } 00142 00143 #endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 00144