1 // Special functions -*- C++ -*-
4 // Free Software Foundation, Inc.
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 2, or (at your option)
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.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file tr1/special_function_util.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
37 // ISO C++ 14882 TR1: 5.2 Special functions
40 // Written by Edward Smith-Rowland based on numerous mathematics books.
42 #ifndef _TR1_SPECIAL_FUNCTION_UTIL_H
43 #define _TR1_SPECIAL_FUNCTION_UTIL_H 1
48 _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1)
54 /// @brief A class to encapsulate type dependent floating point
55 /// constants. Not everything will be able to be expressed
58 template <typename _Tp>
59 struct __floating_point_constant
61 static const _Tp __value;
66 /// @brief A structure for numeric constants.
68 template<typename _Tp>
69 struct __numeric_constants
71 /// Constant @f$ \pi @f$.
72 static _Tp __pi() throw()
73 { return static_cast<_Tp>(3.1415926535897932384626433832795029L); }
74 /// Constant @f$ \pi / 2 @f$.
75 static _Tp __pi_2() throw()
76 { return static_cast<_Tp>(1.5707963267948966192313216916397514L); }
77 /// Constant @f$ \pi / 3 @f$.
78 static _Tp __pi_3() throw()
79 { return static_cast<_Tp>(1.0471975511965977461542144610931676L); }
80 /// Constant @f$ \pi / 4 @f$.
81 static _Tp __pi_4() throw()
82 { return static_cast<_Tp>(0.7853981633974483096156608458198757L); }
83 /// Constant @f$ 1 / \pi @f$.
84 static _Tp __1_pi() throw()
85 { return static_cast<_Tp>(0.3183098861837906715377675267450287L); }
86 /// Constant @f$ 2 / \sqrt(\pi) @f$.
87 static _Tp __2_sqrtpi() throw()
88 { return static_cast<_Tp>(1.1283791670955125738961589031215452L); }
89 /// Constant @f$ \sqrt(2) @f$.
90 static _Tp __sqrt2() throw()
91 { return static_cast<_Tp>(1.4142135623730950488016887242096981L); }
92 /// Constant @f$ \sqrt(3) @f$.
93 static _Tp __sqrt3() throw()
94 { return static_cast<_Tp>(1.7320508075688772935274463415058723L); }
95 /// Constant @f$ \sqrt(\pi/2) @f$.
96 static _Tp __sqrtpio2() throw()
97 { return static_cast<_Tp>(1.2533141373155002512078826424055226L); }
98 /// Constant @f$ 1 / sqrt(2) @f$.
99 static _Tp __sqrt1_2() throw()
100 { return static_cast<_Tp>(0.7071067811865475244008443621048490L); }
101 /// Constant @f$ \log(\pi) @f$.
102 static _Tp __lnpi() throw()
103 { return static_cast<_Tp>(1.1447298858494001741434273513530587L); }
104 /// Constant Euler's constant @f$ \gamma_E @f$.
105 static _Tp __gamma_e() throw()
106 { return static_cast<_Tp>(0.5772156649015328606065120900824024L); }
107 /// Constant Euler-Mascheroni @f$ e @f$
108 static _Tp __euler() throw()
109 { return static_cast<_Tp>(2.7182818284590452353602874713526625L); }
114 /// @brief This is a wrapper for the isnan function.
115 /// Otherwise, for NaN, all comparisons result in false.
116 /// If/when we build a std::isnan out of intrinsics, this
117 /// will disappear completely in favor of std::isnan.
119 #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
121 template <typename _Tp>
122 inline bool __isnan(const _Tp __x)
124 return std::isnan(__x);
129 template <typename _Tp>
130 inline bool __isnan(const _Tp __x)
132 return __builtin_isnan(__x);
136 inline bool __isnan<float>(const float __x)
138 return __builtin_isnanf(__x);
142 inline bool __isnan<long double>(const long double __x)
144 return __builtin_isnanl(__x);
149 } // namespace __detail
151 _GLIBCXX_END_NAMESPACE
154 #endif // _TR1_SPECIAL_FUNCTION_UTIL_H