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