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