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