]>
Commit | Line | Data |
---|---|---|
7c62b943 BK |
1 | // Special functions -*- C++ -*- |
2 | ||
3 | // Copyright (C) 2006 | |
4 | // Free Software Foundation, Inc. | |
5 | // | |
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) | |
10 | // any later version. | |
11 | ||
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. | |
16 | ||
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, | |
20 | // USA. | |
21 | ||
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. | |
30 | ||
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. | |
34 | */ | |
35 | ||
36 | // | |
37 | // ISO C++ 14882 TR1: 5.2 Special functions | |
38 | // | |
39 | ||
40 | // Written by Edward Smith-Rowland based on numerous mathematics books. | |
41 | ||
e133ace8 PC |
42 | #ifndef _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H |
43 | #define _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H 1 | |
7c62b943 BK |
44 | |
45 | // namespace std::tr1 | |
46 | namespace std | |
47 | { | |
e133ace8 PC |
48 | namespace tr1 |
49 | { | |
7c62b943 BK |
50 | |
51 | namespace __detail | |
52 | { | |
53 | ||
54 | /// | |
55 | /// @brief A class to encapsulate type dependent floating point | |
56 | /// constants. Not everything will be able to be expressed | |
57 | /// as type logic. | |
58 | /// | |
59 | template <typename _Tp> | |
60 | struct __floating_point_constant | |
61 | { | |
62 | static const _Tp __value; | |
63 | }; | |
64 | ||
65 | ||
66 | /// | |
67 | /// @brief A structure for numeric constants. | |
68 | /// | |
69 | template<typename _Tp> | |
70 | struct __numeric_constants | |
71 | { | |
72 | /// Constant @f$ \pi @f$. | |
73 | static _Tp __pi() throw() | |
74 | { return static_cast<_Tp>(3.1415926535897932384626433832795029L); } | |
75 | /// Constant @f$ \pi / 2 @f$. | |
76 | static _Tp __pi_2() throw() | |
77 | { return static_cast<_Tp>(1.5707963267948966192313216916397514L); } | |
78 | /// Constant @f$ \pi / 3 @f$. | |
79 | static _Tp __pi_3() throw() | |
80 | { return static_cast<_Tp>(1.0471975511965977461542144610931676L); } | |
81 | /// Constant @f$ \pi / 4 @f$. | |
82 | static _Tp __pi_4() throw() | |
83 | { return static_cast<_Tp>(0.7853981633974483096156608458198757L); } | |
84 | /// Constant @f$ 1 / \pi @f$. | |
85 | static _Tp __1_pi() throw() | |
86 | { return static_cast<_Tp>(0.3183098861837906715377675267450287L); } | |
87 | /// Constant @f$ 2 / \sqrt(\pi) @f$. | |
88 | static _Tp __2_sqrtpi() throw() | |
89 | { return static_cast<_Tp>(1.1283791670955125738961589031215452L); } | |
90 | /// Constant @f$ \sqrt(2) @f$. | |
91 | static _Tp __sqrt2() throw() | |
92 | { return static_cast<_Tp>(1.4142135623730950488016887242096981L); } | |
93 | /// Constant @f$ \sqrt(3) @f$. | |
94 | static _Tp __sqrt3() throw() | |
95 | { return static_cast<_Tp>(1.7320508075688772935274463415058723L); } | |
96 | /// Constant @f$ \sqrt(\pi/2) @f$. | |
97 | static _Tp __sqrtpio2() throw() | |
98 | { return static_cast<_Tp>(1.2533141373155002512078826424055226L); } | |
99 | /// Constant @f$ 1 / sqrt(2) @f$. | |
100 | static _Tp __sqrt1_2() throw() | |
101 | { return static_cast<_Tp>(0.7071067811865475244008443621048490L); } | |
102 | /// Constant @f$ \log(\pi) @f$. | |
103 | static _Tp __lnpi() throw() | |
104 | { return static_cast<_Tp>(1.1447298858494001741434273513530587L); } | |
105 | /// Constant Euler's constant @f$ \gamma_E @f$. | |
106 | static _Tp __gamma_e() throw() | |
107 | { return static_cast<_Tp>(0.5772156649015328606065120900824024L); } | |
108 | /// Constant Euler-Mascheroni @f$ e @f$ | |
109 | static _Tp __euler() throw() | |
110 | { return static_cast<_Tp>(2.7182818284590452353602874713526625L); } | |
111 | }; | |
112 | ||
113 | ||
114 | /// | |
115 | /// @brief This is a wrapper for the isnan function. | |
116 | /// Otherwise, for NaN, all comparisons result in false. | |
117 | /// If/when we build a std::isnan out of intrinsics, this | |
118 | /// will disappear completely in favor of std::isnan. | |
119 | /// | |
120 | #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC | |
121 | ||
122 | template <typename _Tp> | |
123 | inline bool __isnan(const _Tp __x) | |
124 | { | |
125 | return std::isnan(__x); | |
126 | } | |
127 | ||
128 | #else | |
129 | ||
130 | template <typename _Tp> | |
131 | inline bool __isnan(const _Tp __x) | |
132 | { | |
133 | return __builtin_isnan(__x); | |
134 | } | |
135 | ||
136 | template <> | |
137 | inline bool __isnan<float>(const float __x) | |
138 | { | |
139 | return __builtin_isnanf(__x); | |
140 | } | |
141 | ||
142 | template <> | |
143 | inline bool __isnan<long double>(const long double __x) | |
144 | { | |
145 | return __builtin_isnanl(__x); | |
146 | } | |
147 | ||
148 | #endif | |
149 | ||
150 | } // namespace __detail | |
151 | ||
e133ace8 | 152 | } |
7c62b943 BK |
153 | } |
154 | ||
e133ace8 | 155 | #endif // _GLIBCXX_TR1_SPECIAL_FUNCTION_UTIL_H |
7c62b943 | 156 |