1// Special functions -*- C++ -*- 2 3// Copyright (C) 2006, 2009 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// Under Section 7 of GPL version 3, you are granted additional 18// permissions described in the GCC Runtime Library Exception, version 19// 3.1, as published by the Free Software Foundation. 20 21// You should have received a copy of the GNU General Public License and 22// a copy of the GCC Runtime Library Exception along with this program; 23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24// <http://www.gnu.org/licenses/>. 25 26/** @file tr1/special_function_util.h 27 * This is an internal header file, included by other library headers. 28 * You should not attempt to use it directly. 29 */ 30 31// 32// ISO C++ 14882 TR1: 5.2 Special functions 33// 34 35// Written by Edward Smith-Rowland based on numerous mathematics books. 36 37#ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 38#define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1 39 40namespace std 41{ 42namespace tr1 43{ 44 45 namespace __detail 46 { 47 48 /// A class to encapsulate type dependent floating point 49 /// constants. Not everything will be able to be expressed as 50 /// type logic. 51 template<typename _Tp> 52 struct __floating_point_constant 53 { 54 static const _Tp __value; 55 }; 56 57 58 /// A structure for numeric constants. 59 template<typename _Tp> 60 struct __numeric_constants 61 { 62 /// Constant @f$ \pi @f$. 63 static _Tp __pi() throw() 64 { return static_cast<_Tp>(3.1415926535897932384626433832795029L); } 65 /// Constant @f$ \pi / 2 @f$. 66 static _Tp __pi_2() throw() 67 { return static_cast<_Tp>(1.5707963267948966192313216916397514L); } 68 /// Constant @f$ \pi / 3 @f$. 69 static _Tp __pi_3() throw() 70 { return static_cast<_Tp>(1.0471975511965977461542144610931676L); } 71 /// Constant @f$ \pi / 4 @f$. 72 static _Tp __pi_4() throw() 73 { return static_cast<_Tp>(0.7853981633974483096156608458198757L); } 74 /// Constant @f$ 1 / \pi @f$. 75 static _Tp __1_pi() throw() 76 { return static_cast<_Tp>(0.3183098861837906715377675267450287L); } 77 /// Constant @f$ 2 / \sqrt(\pi) @f$. 78 static _Tp __2_sqrtpi() throw() 79 { return static_cast<_Tp>(1.1283791670955125738961589031215452L); } 80 /// Constant @f$ \sqrt(2) @f$. 81 static _Tp __sqrt2() throw() 82 { return static_cast<_Tp>(1.4142135623730950488016887242096981L); } 83 /// Constant @f$ \sqrt(3) @f$. 84 static _Tp __sqrt3() throw() 85 { return static_cast<_Tp>(1.7320508075688772935274463415058723L); } 86 /// Constant @f$ \sqrt(\pi/2) @f$. 87 static _Tp __sqrtpio2() throw() 88 { return static_cast<_Tp>(1.2533141373155002512078826424055226L); } 89 /// Constant @f$ 1 / sqrt(2) @f$. 90 static _Tp __sqrt1_2() throw() 91 { return static_cast<_Tp>(0.7071067811865475244008443621048490L); } 92 /// Constant @f$ \log(\pi) @f$. 93 static _Tp __lnpi() throw() 94 { return static_cast<_Tp>(1.1447298858494001741434273513530587L); } 95 /// Constant Euler's constant @f$ \gamma_E @f$. 96 static _Tp __gamma_e() throw() 97 { return static_cast<_Tp>(0.5772156649015328606065120900824024L); } 98 /// Constant Euler-Mascheroni @f$ e @f$ 99 static _Tp __euler() throw() 100 { return static_cast<_Tp>(2.7182818284590452353602874713526625L); } 101 }; 102 103 104#if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC 105 106 /// This is a wrapper for the isnan function. Otherwise, for NaN, 107 /// all comparisons result in false. If/when we build a std::isnan 108 /// out of intrinsics, this will disappear completely in favor of 109 /// std::isnan. 110 template<typename _Tp> 111 inline bool __isnan(const _Tp __x) 112 { 113 return std::isnan(__x); 114 } 115 116#else 117 118 template<typename _Tp> 119 inline bool __isnan(const _Tp __x) 120 { 121 return __builtin_isnan(__x); 122 } 123 124 template<> 125 inline bool __isnan<float>(const float __x) 126 { 127 return __builtin_isnanf(__x); 128 } 129 130 template<> 131 inline bool __isnan<long double>(const long double __x) 132 { 133 return __builtin_isnanl(__x); 134 } 135 136#endif 137 138 } // namespace __detail 139 140} 141} 142 143#endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 144 145