STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
beta_function.tcc File Reference

Macros

#define _GLIBCXX_TR1_BETA_FUNCTION_TCC   1
 

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {tr1/cmath}

Macro Definition Documentation

#define _GLIBCXX_TR1_BETA_FUNCTION_TCC   1

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Return the beta function: $B(x,y)$.

The beta function is defined by

\[ B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} \]

Parameters
__xThe first argument of the beta function.
__yThe second argument of the beta function.
Returns
The beta function.

Return the beta function $B(x,y)$ using the log gamma functions.

The beta function is defined by

\[ B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} \]

Parameters
__xThe first argument of the beta function.
__yThe second argument of the beta function.
Returns
The beta function.

Return the beta function $B(x,y)$ using the product form.

The beta function is defined by

\[ B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} \]

Parameters
__xThe first argument of the beta function.
__yThe second argument of the beta function.
Returns
The beta function.

Return the beta function $ B(x,y) $.

The beta function is defined by

\[ B(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} \]

Parameters
__xThe first argument of the beta function.
__yThe second argument of the beta function.
Returns
The beta function.
50 {
51 namespace tr1
52 {
53  // [5.2] Special functions
54 
55  // Implementation-space details.
56  namespace __detail
57  {
58  _GLIBCXX_BEGIN_NAMESPACE_VERSION
59 
72  template<typename _Tp>
73  _Tp
74  __beta_gamma(_Tp __x, _Tp __y)
75  {
76 
77  _Tp __bet;
78 #if _GLIBCXX_USE_C99_MATH_TR1
79  if (__x > __y)
80  {
81  __bet = std::tr1::tgamma(__x)
82  / std::tr1::tgamma(__x + __y);
83  __bet *= std::tr1::tgamma(__y);
84  }
85  else
86  {
87  __bet = std::tr1::tgamma(__y)
88  / std::tr1::tgamma(__x + __y);
89  __bet *= std::tr1::tgamma(__x);
90  }
91 #else
92  if (__x > __y)
93  {
94  __bet = __gamma(__x) / __gamma(__x + __y);
95  __bet *= __gamma(__y);
96  }
97  else
98  {
99  __bet = __gamma(__y) / __gamma(__x + __y);
100  __bet *= __gamma(__x);
101  }
102 #endif
103 
104  return __bet;
105  }
106 
120  template<typename _Tp>
121  _Tp
122  __beta_lgamma(_Tp __x, _Tp __y)
123  {
124 #if _GLIBCXX_USE_C99_MATH_TR1
125  _Tp __bet = std::tr1::lgamma(__x)
126  + std::tr1::lgamma(__y)
127  - std::tr1::lgamma(__x + __y);
128 #else
129  _Tp __bet = __log_gamma(__x)
130  + __log_gamma(__y)
131  - __log_gamma(__x + __y);
132 #endif
133  __bet = std::exp(__bet);
134  return __bet;
135  }
136 
137 
151  template<typename _Tp>
152  _Tp
153  __beta_product(_Tp __x, _Tp __y)
154  {
155 
156  _Tp __bet = (__x + __y) / (__x * __y);
157 
158  unsigned int __max_iter = 1000000;
159  for (unsigned int __k = 1; __k < __max_iter; ++__k)
160  {
161  _Tp __term = (_Tp(1) + (__x + __y) / __k)
162  / ((_Tp(1) + __x / __k) * (_Tp(1) + __y / __k));
163  __bet *= __term;
164  }
165 
166  return __bet;
167  }
168 
169 
182  template<typename _Tp>
183  inline _Tp
184  __beta(_Tp __x, _Tp __y)
185  {
186  if (__isnan(__x) || __isnan(__y))
187  return std::numeric_limits<_Tp>::quiet_NaN();
188  else
189  return __beta_lgamma(__x, __y);
190  }
191 
192  _GLIBCXX_END_NAMESPACE_VERSION
193  } // namespace std::tr1::__detail
194 }
195 }