xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/tr1/special_function_util.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg // Special functions -*- C++ -*-
236ac495dSmrg 
3*8feb0f0bSmrg // Copyright (C) 2006-2020 Free Software Foundation, Inc.
436ac495dSmrg //
536ac495dSmrg // This file is part of the GNU ISO C++ Library.  This library is free
636ac495dSmrg // software; you can redistribute it and/or modify it under the
736ac495dSmrg // terms of the GNU General Public License as published by the
836ac495dSmrg // Free Software Foundation; either version 3, or (at your option)
936ac495dSmrg // any later version.
1036ac495dSmrg 
1136ac495dSmrg // This library is distributed in the hope that it will be useful,
1236ac495dSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1336ac495dSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1436ac495dSmrg // GNU General Public License for more details.
1536ac495dSmrg 
1636ac495dSmrg // Under Section 7 of GPL version 3, you are granted additional
1736ac495dSmrg // permissions described in the GCC Runtime Library Exception, version
1836ac495dSmrg // 3.1, as published by the Free Software Foundation.
1936ac495dSmrg 
2036ac495dSmrg // You should have received a copy of the GNU General Public License and
2136ac495dSmrg // a copy of the GCC Runtime Library Exception along with this program;
2236ac495dSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2336ac495dSmrg // <http://www.gnu.org/licenses/>.
2436ac495dSmrg 
2536ac495dSmrg /** @file tr1/special_function_util.h
2636ac495dSmrg  *  This is an internal header file, included by other library headers.
2736ac495dSmrg  *  Do not attempt to use it directly. @headername{tr1/cmath}
2836ac495dSmrg  */
2936ac495dSmrg 
3036ac495dSmrg //
3136ac495dSmrg // ISO C++ 14882 TR1: 5.2  Special functions
3236ac495dSmrg //
3336ac495dSmrg 
3436ac495dSmrg // Written by Edward Smith-Rowland based on numerous mathematics books.
3536ac495dSmrg 
3636ac495dSmrg #ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H
3736ac495dSmrg #define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1
3836ac495dSmrg 
_GLIBCXX_VISIBILITY(default)3936ac495dSmrg namespace std _GLIBCXX_VISIBILITY(default)
4036ac495dSmrg {
41a2dc1f3fSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
42a2dc1f3fSmrg 
4336ac495dSmrg #if _GLIBCXX_USE_STD_SPEC_FUNCS
4436ac495dSmrg #elif defined(_GLIBCXX_TR1_CMATH)
4536ac495dSmrg namespace tr1
4636ac495dSmrg {
4736ac495dSmrg #else
4836ac495dSmrg # error do not include this header directly, use <cmath> or <tr1/cmath>
4936ac495dSmrg #endif
5036ac495dSmrg   namespace __detail
5136ac495dSmrg   {
5236ac495dSmrg     /// A class to encapsulate type dependent floating point
5336ac495dSmrg     /// constants.  Not everything will be able to be expressed as
5436ac495dSmrg     /// type logic.
5536ac495dSmrg     template<typename _Tp>
5636ac495dSmrg     struct __floating_point_constant
5736ac495dSmrg     {
5836ac495dSmrg       static const _Tp __value;
5936ac495dSmrg     };
6036ac495dSmrg 
6136ac495dSmrg 
6236ac495dSmrg     /// A structure for numeric constants.
6336ac495dSmrg     template<typename _Tp>
6436ac495dSmrg       struct __numeric_constants
6536ac495dSmrg       {
6636ac495dSmrg         ///  Constant @f$ \pi @f$.
6736ac495dSmrg         static _Tp __pi() throw()
6836ac495dSmrg         { return static_cast<_Tp>(3.1415926535897932384626433832795029L); }
6936ac495dSmrg         ///  Constant @f$ \pi / 2 @f$.
7036ac495dSmrg         static _Tp __pi_2() throw()
7136ac495dSmrg         { return static_cast<_Tp>(1.5707963267948966192313216916397514L); }
7236ac495dSmrg         ///  Constant @f$ \pi / 3 @f$.
7336ac495dSmrg         static _Tp __pi_3() throw()
7436ac495dSmrg         { return static_cast<_Tp>(1.0471975511965977461542144610931676L); }
7536ac495dSmrg         ///  Constant @f$ \pi / 4 @f$.
7636ac495dSmrg         static _Tp __pi_4() throw()
7736ac495dSmrg         { return static_cast<_Tp>(0.7853981633974483096156608458198757L); }
7836ac495dSmrg         ///  Constant @f$ 1 / \pi @f$.
7936ac495dSmrg         static _Tp __1_pi() throw()
8036ac495dSmrg         { return static_cast<_Tp>(0.3183098861837906715377675267450287L); }
8136ac495dSmrg         ///  Constant @f$ 2 / \sqrt(\pi) @f$.
8236ac495dSmrg         static _Tp __2_sqrtpi() throw()
8336ac495dSmrg         { return static_cast<_Tp>(1.1283791670955125738961589031215452L); }
8436ac495dSmrg         ///  Constant @f$ \sqrt(2) @f$.
8536ac495dSmrg         static _Tp __sqrt2() throw()
8636ac495dSmrg         { return static_cast<_Tp>(1.4142135623730950488016887242096981L); }
8736ac495dSmrg         ///  Constant @f$ \sqrt(3) @f$.
8836ac495dSmrg         static _Tp __sqrt3() throw()
8936ac495dSmrg         { return static_cast<_Tp>(1.7320508075688772935274463415058723L); }
9036ac495dSmrg         ///  Constant @f$ \sqrt(\pi/2) @f$.
9136ac495dSmrg         static _Tp __sqrtpio2() throw()
9236ac495dSmrg         { return static_cast<_Tp>(1.2533141373155002512078826424055226L); }
9336ac495dSmrg         ///  Constant @f$ 1 / sqrt(2) @f$.
9436ac495dSmrg         static _Tp __sqrt1_2() throw()
9536ac495dSmrg         { return static_cast<_Tp>(0.7071067811865475244008443621048490L); }
9636ac495dSmrg         ///  Constant @f$ \log(\pi) @f$.
9736ac495dSmrg         static _Tp __lnpi() throw()
9836ac495dSmrg         { return static_cast<_Tp>(1.1447298858494001741434273513530587L); }
9936ac495dSmrg         ///  Constant Euler's constant @f$ \gamma_E @f$.
10036ac495dSmrg         static _Tp __gamma_e() throw()
10136ac495dSmrg         { return static_cast<_Tp>(0.5772156649015328606065120900824024L); }
10236ac495dSmrg         ///  Constant Euler-Mascheroni @f$ e @f$
10336ac495dSmrg         static _Tp __euler() throw()
10436ac495dSmrg         { return static_cast<_Tp>(2.7182818284590452353602874713526625L); }
10536ac495dSmrg       };
10636ac495dSmrg 
10736ac495dSmrg 
10836ac495dSmrg #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
10936ac495dSmrg 
11036ac495dSmrg     /// This is a wrapper for the isnan function. Otherwise, for NaN,
11136ac495dSmrg     /// all comparisons result in false. If/when we build a std::isnan
11236ac495dSmrg     /// out of intrinsics, this will disappear completely in favor of
11336ac495dSmrg     /// std::isnan.
11436ac495dSmrg     template<typename _Tp>
11536ac495dSmrg     inline bool __isnan(_Tp __x)
11636ac495dSmrg     { return std::isnan(__x); }
11736ac495dSmrg 
11836ac495dSmrg #else
11936ac495dSmrg 
12036ac495dSmrg     template<typename _Tp>
12136ac495dSmrg     inline bool __isnan(const _Tp __x)
12236ac495dSmrg     { return __builtin_isnan(__x); }
12336ac495dSmrg 
12436ac495dSmrg     template<>
12536ac495dSmrg     inline bool __isnan<float>(float __x)
12636ac495dSmrg     { return __builtin_isnanf(__x); }
12736ac495dSmrg 
12836ac495dSmrg     template<>
12936ac495dSmrg     inline bool __isnan<long double>(long double __x)
13036ac495dSmrg     { return __builtin_isnanl(__x); }
13136ac495dSmrg 
13236ac495dSmrg #endif
13336ac495dSmrg   } // namespace __detail
13436ac495dSmrg #if ! _GLIBCXX_USE_STD_SPEC_FUNCS && defined(_GLIBCXX_TR1_CMATH)
13536ac495dSmrg } // namespace tr1
13636ac495dSmrg #endif
137a2dc1f3fSmrg 
138a2dc1f3fSmrg _GLIBCXX_END_NAMESPACE_VERSION
13936ac495dSmrg }
14036ac495dSmrg 
14136ac495dSmrg #endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H
14236ac495dSmrg 
143