OSDN Git Service

2007-04-09 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / special_function_util.h
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
42 #ifndef _TR1_SPECIAL_FUNCTION_UTIL_H
43 #define _TR1_SPECIAL_FUNCTION_UTIL_H 1
44
45 // namespace std::tr1
46 namespace std
47 {
48 _GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1)
49
50   namespace __detail
51   {
52
53     ///
54     ///  @brief  A class to encapsulate type dependent floating point
55     ///          constants.  Not everything will be able to be expressed
56     ///          as type logic.
57     ///
58     template <typename _Tp>
59     struct __floating_point_constant
60     {
61       static const _Tp __value;
62     };
63
64
65     ///
66     ///  @brief  A structure for numeric constants.
67     ///
68     template<typename _Tp>
69       struct __numeric_constants
70       {
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); }
110       };
111
112
113     ///
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.
118     ///
119 #if _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
120
121     template <typename _Tp>
122     inline bool __isnan(const _Tp __x)
123     {
124       return std::isnan(__x);
125     }
126
127 #else
128
129     template <typename _Tp>
130     inline bool __isnan(const _Tp __x)
131     {
132       return __builtin_isnan(__x);
133     }
134
135     template <>
136     inline bool __isnan<float>(const float __x)
137     {
138       return __builtin_isnanf(__x);
139     }
140
141     template <>
142     inline bool __isnan<long double>(const long double __x)
143     {
144       return __builtin_isnanl(__x);
145     }
146
147 #endif
148
149   } // namespace __detail
150
151 _GLIBCXX_END_NAMESPACE
152 }
153
154 #endif // _TR1_SPECIAL_FUNCTION_UTIL_H
155