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

Macros

#define _GLIBCXX_TR1_HYPERGEOMETRIC_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_HYPERGEOMETRIC_TCC   1

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

This routine returns the confluent hypergeometric function by series expansion.

\[ _1F_1(a;c;x) = \frac{\Gamma(c)}{\Gamma(a)} \sum_{n=0}^{\infty} \frac{\Gamma(a+n)}{\Gamma(c+n)} \frac{x^n}{n!} \]

If a and b are integers and a < 0 and either b > 0 or b < a then the series is a polynomial with a finite number of terms. If b is an integer and b <= 0 the confluent hypergeometric function is undefined.

Parameters
__aThe "numerator" parameter.
__cThe "denominator" parameter.
__xThe argument of the confluent hypergeometric function.
Returns
The confluent hypergeometric function.

Return the hypogeometric function $ _2F_1(a,b;c;x) $ by an iterative procedure described in Luke, Algorithms for the Computation of Mathematical Functions.

Like the case of the 2F1 rational approximations, these are probably guaranteed to converge for x < 0, barring gross numerical instability in the pre-asymptotic regime.

Return the confluent hypogeometric function $ _1F_1(a;c;x) $.

Todo:
Handle b == nonpositive integer blowup - return NaN.
Parameters
__aThe numerator parameter.
__cThe denominator parameter.
__xThe argument of the confluent hypergeometric function.
Returns
The confluent hypergeometric function.

Return the hypogeometric function $ _2F_1(a,b;c;x) $ by series expansion.

The hypogeometric function is defined by

\[ _2F_1(a,b;c;x) = \frac{\Gamma(c)}{\Gamma(a)\Gamma(b)} \sum_{n=0}^{\infty} \frac{\Gamma(a+n)\Gamma(b+n)}{\Gamma(c+n)} \frac{x^n}{n!} \]

This works and it's pretty fast.

Parameters
__aThe first numerator parameter.
__aThe second numerator parameter.
__cThe denominator parameter.
__xThe argument of the confluent hypergeometric function.
Returns
The confluent hypergeometric function.

Return the hypogeometric function $ _2F_1(a,b;c;x) $ by an iterative procedure described in Luke, Algorithms for the Computation of Mathematical Functions.

Return the hypogeometric function $ _2F_1(a,b;c;x) $ by the reflection formulae in Abramowitz & Stegun formula 15.3.6 for d = c - a - b not integral and formula 15.3.11 for d = c - a - b integral. This assumes a, b, c != negative integer.

The hypogeometric function is defined by

\[ _2F_1(a,b;c;x) = \frac{\Gamma(c)}{\Gamma(a)\Gamma(b)} \sum_{n=0}^{\infty} \frac{\Gamma(a+n)\Gamma(b+n)}{\Gamma(c+n)} \frac{x^n}{n!} \]

The reflection formula for nonintegral $ d = c - a - b $ is:

\[ _2F_1(a,b;c;x) = \frac{\Gamma(c)\Gamma(d)}{\Gamma(c-a)\Gamma(c-b)} _2F_1(a,b;1-d;1-x) + \frac{\Gamma(c)\Gamma(-d)}{\Gamma(a)\Gamma(b)} _2F_1(c-a,c-b;1+d;1-x) \]

The reflection formula for integral $ m = c - a - b $ is:

\[ _2F_1(a,b;a+b+m;x) = \frac{\Gamma(m)\Gamma(a+b+m)}{\Gamma(a+m)\Gamma(b+m)} \sum_{k=0}^{m-1} \frac{(m+a)_k(m+b)_k}{k!(1-m)_k} - \]

Return the hypogeometric function $ _2F_1(a,b;c;x) $.

The hypogeometric function is defined by

\[ _2F_1(a,b;c;x) = \frac{\Gamma(c)}{\Gamma(a)\Gamma(b)} \sum_{n=0}^{\infty} \frac{\Gamma(a+n)\Gamma(b+n)}{\Gamma(c+n)} \frac{x^n}{n!} \]

Parameters
__aThe first numerator parameter.
__aThe second numerator parameter.
__cThe denominator parameter.
__xThe argument of the confluent hypergeometric function.
Returns
The confluent hypergeometric function.
45 {
46 namespace tr1
47 {
48  // [5.2] Special functions
49 
50  // Implementation-space details.
51  namespace __detail
52  {
53  _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 
76  template<typename _Tp>
77  _Tp
78  __conf_hyperg_series(_Tp __a, _Tp __c, _Tp __x)
79  {
80  const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
81 
82  _Tp __term = _Tp(1);
83  _Tp __Fac = _Tp(1);
84  const unsigned int __max_iter = 100000;
85  unsigned int __i;
86  for (__i = 0; __i < __max_iter; ++__i)
87  {
88  __term *= (__a + _Tp(__i)) * __x
89  / ((__c + _Tp(__i)) * _Tp(1 + __i));
90  if (std::abs(__term) < __eps)
91  {
92  break;
93  }
94  __Fac += __term;
95  }
96  if (__i == __max_iter)
97  std::__throw_runtime_error(__N("Series failed to converge "
98  "in __conf_hyperg_series."));
99 
100  return __Fac;
101  }
102 
103 
113  template<typename _Tp>
114  _Tp
115  __conf_hyperg_luke(_Tp __a, _Tp __c, _Tp __xin)
116  {
117  const _Tp __big = std::pow(std::numeric_limits<_Tp>::max(), _Tp(0.16L));
118  const int __nmax = 20000;
119  const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
120  const _Tp __x = -__xin;
121  const _Tp __x3 = __x * __x * __x;
122  const _Tp __t0 = __a / __c;
123  const _Tp __t1 = (__a + _Tp(1)) / (_Tp(2) * __c);
124  const _Tp __t2 = (__a + _Tp(2)) / (_Tp(2) * (__c + _Tp(1)));
125  _Tp __F = _Tp(1);
126  _Tp __prec;
127 
128  _Tp __Bnm3 = _Tp(1);
129  _Tp __Bnm2 = _Tp(1) + __t1 * __x;
130  _Tp __Bnm1 = _Tp(1) + __t2 * __x * (_Tp(1) + __t1 / _Tp(3) * __x);
131 
132  _Tp __Anm3 = _Tp(1);
133  _Tp __Anm2 = __Bnm2 - __t0 * __x;
134  _Tp __Anm1 = __Bnm1 - __t0 * (_Tp(1) + __t2 * __x) * __x
135  + __t0 * __t1 * (__c / (__c + _Tp(1))) * __x * __x;
136 
137  int __n = 3;
138  while(1)
139  {
140  _Tp __npam1 = _Tp(__n - 1) + __a;
141  _Tp __npcm1 = _Tp(__n - 1) + __c;
142  _Tp __npam2 = _Tp(__n - 2) + __a;
143  _Tp __npcm2 = _Tp(__n - 2) + __c;
144  _Tp __tnm1 = _Tp(2 * __n - 1);
145  _Tp __tnm3 = _Tp(2 * __n - 3);
146  _Tp __tnm5 = _Tp(2 * __n - 5);
147  _Tp __F1 = (_Tp(__n - 2) - __a) / (_Tp(2) * __tnm3 * __npcm1);
148  _Tp __F2 = (_Tp(__n) + __a) * __npam1
149  / (_Tp(4) * __tnm1 * __tnm3 * __npcm2 * __npcm1);
150  _Tp __F3 = -__npam2 * __npam1 * (_Tp(__n - 2) - __a)
151  / (_Tp(8) * __tnm3 * __tnm3 * __tnm5
152  * (_Tp(__n - 3) + __c) * __npcm2 * __npcm1);
153  _Tp __E = -__npam1 * (_Tp(__n - 1) - __c)
154  / (_Tp(2) * __tnm3 * __npcm2 * __npcm1);
155 
156  _Tp __An = (_Tp(1) + __F1 * __x) * __Anm1
157  + (__E + __F2 * __x) * __x * __Anm2 + __F3 * __x3 * __Anm3;
158  _Tp __Bn = (_Tp(1) + __F1 * __x) * __Bnm1
159  + (__E + __F2 * __x) * __x * __Bnm2 + __F3 * __x3 * __Bnm3;
160  _Tp __r = __An / __Bn;
161 
162  __prec = std::abs((__F - __r) / __F);
163  __F = __r;
164 
165  if (__prec < __eps || __n > __nmax)
166  break;
167 
168  if (std::abs(__An) > __big || std::abs(__Bn) > __big)
169  {
170  __An /= __big;
171  __Bn /= __big;
172  __Anm1 /= __big;
173  __Bnm1 /= __big;
174  __Anm2 /= __big;
175  __Bnm2 /= __big;
176  __Anm3 /= __big;
177  __Bnm3 /= __big;
178  }
179  else if (std::abs(__An) < _Tp(1) / __big
180  || std::abs(__Bn) < _Tp(1) / __big)
181  {
182  __An *= __big;
183  __Bn *= __big;
184  __Anm1 *= __big;
185  __Bnm1 *= __big;
186  __Anm2 *= __big;
187  __Bnm2 *= __big;
188  __Anm3 *= __big;
189  __Bnm3 *= __big;
190  }
191 
192  ++__n;
193  __Bnm3 = __Bnm2;
194  __Bnm2 = __Bnm1;
195  __Bnm1 = __Bn;
196  __Anm3 = __Anm2;
197  __Anm2 = __Anm1;
198  __Anm1 = __An;
199  }
200 
201  if (__n >= __nmax)
202  std::__throw_runtime_error(__N("Iteration failed to converge "
203  "in __conf_hyperg_luke."));
204 
205  return __F;
206  }
207 
208 
220  template<typename _Tp>
221  _Tp
222  __conf_hyperg(_Tp __a, _Tp __c, _Tp __x)
223  {
224 #if _GLIBCXX_USE_C99_MATH_TR1
225  const _Tp __c_nint = std::tr1::nearbyint(__c);
226 #else
227  const _Tp __c_nint = static_cast<int>(__c + _Tp(0.5L));
228 #endif
229  if (__isnan(__a) || __isnan(__c) || __isnan(__x))
230  return std::numeric_limits<_Tp>::quiet_NaN();
231  else if (__c_nint == __c && __c_nint <= 0)
232  return std::numeric_limits<_Tp>::infinity();
233  else if (__a == _Tp(0))
234  return _Tp(1);
235  else if (__c == __a)
236  return std::exp(__x);
237  else if (__x < _Tp(0))
238  return __conf_hyperg_luke(__a, __c, __x);
239  else
240  return __conf_hyperg_series(__a, __c, __x);
241  }
242 
243 
264  template<typename _Tp>
265  _Tp
266  __hyperg_series(_Tp __a, _Tp __b, _Tp __c, _Tp __x)
267  {
268  const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
269 
270  _Tp __term = _Tp(1);
271  _Tp __Fabc = _Tp(1);
272  const unsigned int __max_iter = 100000;
273  unsigned int __i;
274  for (__i = 0; __i < __max_iter; ++__i)
275  {
276  __term *= (__a + _Tp(__i)) * (__b + _Tp(__i)) * __x
277  / ((__c + _Tp(__i)) * _Tp(1 + __i));
278  if (std::abs(__term) < __eps)
279  {
280  break;
281  }
282  __Fabc += __term;
283  }
284  if (__i == __max_iter)
285  std::__throw_runtime_error(__N("Series failed to converge "
286  "in __hyperg_series."));
287 
288  return __Fabc;
289  }
290 
291 
297  template<typename _Tp>
298  _Tp
299  __hyperg_luke(_Tp __a, _Tp __b, _Tp __c, _Tp __xin)
300  {
301  const _Tp __big = std::pow(std::numeric_limits<_Tp>::max(), _Tp(0.16L));
302  const int __nmax = 20000;
303  const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
304  const _Tp __x = -__xin;
305  const _Tp __x3 = __x * __x * __x;
306  const _Tp __t0 = __a * __b / __c;
307  const _Tp __t1 = (__a + _Tp(1)) * (__b + _Tp(1)) / (_Tp(2) * __c);
308  const _Tp __t2 = (__a + _Tp(2)) * (__b + _Tp(2))
309  / (_Tp(2) * (__c + _Tp(1)));
310 
311  _Tp __F = _Tp(1);
312 
313  _Tp __Bnm3 = _Tp(1);
314  _Tp __Bnm2 = _Tp(1) + __t1 * __x;
315  _Tp __Bnm1 = _Tp(1) + __t2 * __x * (_Tp(1) + __t1 / _Tp(3) * __x);
316 
317  _Tp __Anm3 = _Tp(1);
318  _Tp __Anm2 = __Bnm2 - __t0 * __x;
319  _Tp __Anm1 = __Bnm1 - __t0 * (_Tp(1) + __t2 * __x) * __x
320  + __t0 * __t1 * (__c / (__c + _Tp(1))) * __x * __x;
321 
322  int __n = 3;
323  while (1)
324  {
325  const _Tp __npam1 = _Tp(__n - 1) + __a;
326  const _Tp __npbm1 = _Tp(__n - 1) + __b;
327  const _Tp __npcm1 = _Tp(__n - 1) + __c;
328  const _Tp __npam2 = _Tp(__n - 2) + __a;
329  const _Tp __npbm2 = _Tp(__n - 2) + __b;
330  const _Tp __npcm2 = _Tp(__n - 2) + __c;
331  const _Tp __tnm1 = _Tp(2 * __n - 1);
332  const _Tp __tnm3 = _Tp(2 * __n - 3);
333  const _Tp __tnm5 = _Tp(2 * __n - 5);
334  const _Tp __n2 = __n * __n;
335  const _Tp __F1 = (_Tp(3) * __n2 + (__a + __b - _Tp(6)) * __n
336  + _Tp(2) - __a * __b - _Tp(2) * (__a + __b))
337  / (_Tp(2) * __tnm3 * __npcm1);
338  const _Tp __F2 = -(_Tp(3) * __n2 - (__a + __b + _Tp(6)) * __n
339  + _Tp(2) - __a * __b) * __npam1 * __npbm1
340  / (_Tp(4) * __tnm1 * __tnm3 * __npcm2 * __npcm1);
341  const _Tp __F3 = (__npam2 * __npam1 * __npbm2 * __npbm1
342  * (_Tp(__n - 2) - __a) * (_Tp(__n - 2) - __b))
343  / (_Tp(8) * __tnm3 * __tnm3 * __tnm5
344  * (_Tp(__n - 3) + __c) * __npcm2 * __npcm1);
345  const _Tp __E = -__npam1 * __npbm1 * (_Tp(__n - 1) - __c)
346  / (_Tp(2) * __tnm3 * __npcm2 * __npcm1);
347 
348  _Tp __An = (_Tp(1) + __F1 * __x) * __Anm1
349  + (__E + __F2 * __x) * __x * __Anm2 + __F3 * __x3 * __Anm3;
350  _Tp __Bn = (_Tp(1) + __F1 * __x) * __Bnm1
351  + (__E + __F2 * __x) * __x * __Bnm2 + __F3 * __x3 * __Bnm3;
352  const _Tp __r = __An / __Bn;
353 
354  const _Tp __prec = std::abs((__F - __r) / __F);
355  __F = __r;
356 
357  if (__prec < __eps || __n > __nmax)
358  break;
359 
360  if (std::abs(__An) > __big || std::abs(__Bn) > __big)
361  {
362  __An /= __big;
363  __Bn /= __big;
364  __Anm1 /= __big;
365  __Bnm1 /= __big;
366  __Anm2 /= __big;
367  __Bnm2 /= __big;
368  __Anm3 /= __big;
369  __Bnm3 /= __big;
370  }
371  else if (std::abs(__An) < _Tp(1) / __big
372  || std::abs(__Bn) < _Tp(1) / __big)
373  {
374  __An *= __big;
375  __Bn *= __big;
376  __Anm1 *= __big;
377  __Bnm1 *= __big;
378  __Anm2 *= __big;
379  __Bnm2 *= __big;
380  __Anm3 *= __big;
381  __Bnm3 *= __big;
382  }
383 
384  ++__n;
385  __Bnm3 = __Bnm2;
386  __Bnm2 = __Bnm1;
387  __Bnm1 = __Bn;
388  __Anm3 = __Anm2;
389  __Anm2 = __Anm1;
390  __Anm1 = __An;
391  }
392 
393  if (__n >= __nmax)
394  std::__throw_runtime_error(__N("Iteration failed to converge "
395  "in __hyperg_luke."));
396 
397  return __F;
398  }
399 
400 
431  template<typename _Tp>
432  _Tp
433  __hyperg_reflect(_Tp __a, _Tp __b, _Tp __c, _Tp __x)
434  {
435  const _Tp __d = __c - __a - __b;
436  const int __intd = std::floor(__d + _Tp(0.5L));
437  const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
438  const _Tp __toler = _Tp(1000) * __eps;
439  const _Tp __log_max = std::log(std::numeric_limits<_Tp>::max());
440  const bool __d_integer = (std::abs(__d - __intd) < __toler);
441 
442  if (__d_integer)
443  {
444  const _Tp __ln_omx = std::log(_Tp(1) - __x);
445  const _Tp __ad = std::abs(__d);
446  _Tp __F1, __F2;
447 
448  _Tp __d1, __d2;
449  if (__d >= _Tp(0))
450  {
451  __d1 = __d;
452  __d2 = _Tp(0);
453  }
454  else
455  {
456  __d1 = _Tp(0);
457  __d2 = __d;
458  }
459 
460  const _Tp __lng_c = __log_gamma(__c);
461 
462  // Evaluate F1.
463  if (__ad < __eps)
464  {
465  // d = c - a - b = 0.
466  __F1 = _Tp(0);
467  }
468  else
469  {
470 
471  bool __ok_d1 = true;
472  _Tp __lng_ad, __lng_ad1, __lng_bd1;
473  __try
474  {
475  __lng_ad = __log_gamma(__ad);
476  __lng_ad1 = __log_gamma(__a + __d1);
477  __lng_bd1 = __log_gamma(__b + __d1);
478  }
479  __catch(...)
480  {
481  __ok_d1 = false;
482  }
483 
484  if (__ok_d1)
485  {
486  /* Gamma functions in the denominator are ok.
487  * Proceed with evaluation.
488  */
489  _Tp __sum1 = _Tp(1);
490  _Tp __term = _Tp(1);
491  _Tp __ln_pre1 = __lng_ad + __lng_c + __d2 * __ln_omx
492  - __lng_ad1 - __lng_bd1;
493 
494  /* Do F1 sum.
495  */
496  for (int __i = 1; __i < __ad; ++__i)
497  {
498  const int __j = __i - 1;
499  __term *= (__a + __d2 + __j) * (__b + __d2 + __j)
500  / (_Tp(1) + __d2 + __j) / __i * (_Tp(1) - __x);
501  __sum1 += __term;
502  }
503 
504  if (__ln_pre1 > __log_max)
505  std::__throw_runtime_error(__N("Overflow of gamma functions"
506  " in __hyperg_luke."));
507  else
508  __F1 = std::exp(__ln_pre1) * __sum1;
509  }
510  else
511  {
512  // Gamma functions in the denominator were not ok.
513  // So the F1 term is zero.
514  __F1 = _Tp(0);
515  }
516  } // end F1 evaluation
517 
518  // Evaluate F2.
519  bool __ok_d2 = true;
520  _Tp __lng_ad2, __lng_bd2;
521  __try
522  {
523  __lng_ad2 = __log_gamma(__a + __d2);
524  __lng_bd2 = __log_gamma(__b + __d2);
525  }
526  __catch(...)
527  {
528  __ok_d2 = false;
529  }
530 
531  if (__ok_d2)
532  {
533  // Gamma functions in the denominator are ok.
534  // Proceed with evaluation.
535  const int __maxiter = 2000;
536  const _Tp __psi_1 = -__numeric_constants<_Tp>::__gamma_e();
537  const _Tp __psi_1pd = __psi(_Tp(1) + __ad);
538  const _Tp __psi_apd1 = __psi(__a + __d1);
539  const _Tp __psi_bpd1 = __psi(__b + __d1);
540 
541  _Tp __psi_term = __psi_1 + __psi_1pd - __psi_apd1
542  - __psi_bpd1 - __ln_omx;
543  _Tp __fact = _Tp(1);
544  _Tp __sum2 = __psi_term;
545  _Tp __ln_pre2 = __lng_c + __d1 * __ln_omx
546  - __lng_ad2 - __lng_bd2;
547 
548  // Do F2 sum.
549  int __j;
550  for (__j = 1; __j < __maxiter; ++__j)
551  {
552  // Values for psi functions use recurrence;
553  // Abramowitz & Stegun 6.3.5
554  const _Tp __term1 = _Tp(1) / _Tp(__j)
555  + _Tp(1) / (__ad + __j);
556  const _Tp __term2 = _Tp(1) / (__a + __d1 + _Tp(__j - 1))
557  + _Tp(1) / (__b + __d1 + _Tp(__j - 1));
558  __psi_term += __term1 - __term2;
559  __fact *= (__a + __d1 + _Tp(__j - 1))
560  * (__b + __d1 + _Tp(__j - 1))
561  / ((__ad + __j) * __j) * (_Tp(1) - __x);
562  const _Tp __delta = __fact * __psi_term;
563  __sum2 += __delta;
564  if (std::abs(__delta) < __eps * std::abs(__sum2))
565  break;
566  }
567  if (__j == __maxiter)
568  std::__throw_runtime_error(__N("Sum F2 failed to converge "
569  "in __hyperg_reflect"));
570 
571  if (__sum2 == _Tp(0))
572  __F2 = _Tp(0);
573  else
574  __F2 = std::exp(__ln_pre2) * __sum2;
575  }
576  else
577  {
578  // Gamma functions in the denominator not ok.
579  // So the F2 term is zero.
580  __F2 = _Tp(0);
581  } // end F2 evaluation
582 
583  const _Tp __sgn_2 = (__intd % 2 == 1 ? -_Tp(1) : _Tp(1));
584  const _Tp __F = __F1 + __sgn_2 * __F2;
585 
586  return __F;
587  }
588  else
589  {
590  // d = c - a - b not an integer.
591 
592  // These gamma functions appear in the denominator, so we
593  // catch their harmless domain errors and set the terms to zero.
594  bool __ok1 = true;
595  _Tp __sgn_g1ca = _Tp(0), __ln_g1ca = _Tp(0);
596  _Tp __sgn_g1cb = _Tp(0), __ln_g1cb = _Tp(0);
597  __try
598  {
599  __sgn_g1ca = __log_gamma_sign(__c - __a);
600  __ln_g1ca = __log_gamma(__c - __a);
601  __sgn_g1cb = __log_gamma_sign(__c - __b);
602  __ln_g1cb = __log_gamma(__c - __b);
603  }
604  __catch(...)
605  {
606  __ok1 = false;
607  }
608 
609  bool __ok2 = true;
610  _Tp __sgn_g2a = _Tp(0), __ln_g2a = _Tp(0);
611  _Tp __sgn_g2b = _Tp(0), __ln_g2b = _Tp(0);
612  __try
613  {
614  __sgn_g2a = __log_gamma_sign(__a);
615  __ln_g2a = __log_gamma(__a);
616  __sgn_g2b = __log_gamma_sign(__b);
617  __ln_g2b = __log_gamma(__b);
618  }
619  __catch(...)
620  {
621  __ok2 = false;
622  }
623 
624  const _Tp __sgn_gc = __log_gamma_sign(__c);
625  const _Tp __ln_gc = __log_gamma(__c);
626  const _Tp __sgn_gd = __log_gamma_sign(__d);
627  const _Tp __ln_gd = __log_gamma(__d);
628  const _Tp __sgn_gmd = __log_gamma_sign(-__d);
629  const _Tp __ln_gmd = __log_gamma(-__d);
630 
631  const _Tp __sgn1 = __sgn_gc * __sgn_gd * __sgn_g1ca * __sgn_g1cb;
632  const _Tp __sgn2 = __sgn_gc * __sgn_gmd * __sgn_g2a * __sgn_g2b;
633 
634  _Tp __pre1, __pre2;
635  if (__ok1 && __ok2)
636  {
637  _Tp __ln_pre1 = __ln_gc + __ln_gd - __ln_g1ca - __ln_g1cb;
638  _Tp __ln_pre2 = __ln_gc + __ln_gmd - __ln_g2a - __ln_g2b
639  + __d * std::log(_Tp(1) - __x);
640  if (__ln_pre1 < __log_max && __ln_pre2 < __log_max)
641  {
642  __pre1 = std::exp(__ln_pre1);
643  __pre2 = std::exp(__ln_pre2);
644  __pre1 *= __sgn1;
645  __pre2 *= __sgn2;
646  }
647  else
648  {
649  std::__throw_runtime_error(__N("Overflow of gamma functions "
650  "in __hyperg_reflect"));
651  }
652  }
653  else if (__ok1 && !__ok2)
654  {
655  _Tp __ln_pre1 = __ln_gc + __ln_gd - __ln_g1ca - __ln_g1cb;
656  if (__ln_pre1 < __log_max)
657  {
658  __pre1 = std::exp(__ln_pre1);
659  __pre1 *= __sgn1;
660  __pre2 = _Tp(0);
661  }
662  else
663  {
664  std::__throw_runtime_error(__N("Overflow of gamma functions "
665  "in __hyperg_reflect"));
666  }
667  }
668  else if (!__ok1 && __ok2)
669  {
670  _Tp __ln_pre2 = __ln_gc + __ln_gmd - __ln_g2a - __ln_g2b
671  + __d * std::log(_Tp(1) - __x);
672  if (__ln_pre2 < __log_max)
673  {
674  __pre1 = _Tp(0);
675  __pre2 = std::exp(__ln_pre2);
676  __pre2 *= __sgn2;
677  }
678  else
679  {
680  std::__throw_runtime_error(__N("Overflow of gamma functions "
681  "in __hyperg_reflect"));
682  }
683  }
684  else
685  {
686  __pre1 = _Tp(0);
687  __pre2 = _Tp(0);
688  std::__throw_runtime_error(__N("Underflow of gamma functions "
689  "in __hyperg_reflect"));
690  }
691 
692  const _Tp __F1 = __hyperg_series(__a, __b, _Tp(1) - __d,
693  _Tp(1) - __x);
694  const _Tp __F2 = __hyperg_series(__c - __a, __c - __b, _Tp(1) + __d,
695  _Tp(1) - __x);
696 
697  const _Tp __F = __pre1 * __F1 + __pre2 * __F2;
698 
699  return __F;
700  }
701  }
702 
703 
721  template<typename _Tp>
722  _Tp
723  __hyperg(_Tp __a, _Tp __b, _Tp __c, _Tp __x)
724  {
725 #if _GLIBCXX_USE_C99_MATH_TR1
726  const _Tp __a_nint = std::tr1::nearbyint(__a);
727  const _Tp __b_nint = std::tr1::nearbyint(__b);
728  const _Tp __c_nint = std::tr1::nearbyint(__c);
729 #else
730  const _Tp __a_nint = static_cast<int>(__a + _Tp(0.5L));
731  const _Tp __b_nint = static_cast<int>(__b + _Tp(0.5L));
732  const _Tp __c_nint = static_cast<int>(__c + _Tp(0.5L));
733 #endif
734  const _Tp __toler = _Tp(1000) * std::numeric_limits<_Tp>::epsilon();
735  if (std::abs(__x) >= _Tp(1))
736  std::__throw_domain_error(__N("Argument outside unit circle "
737  "in __hyperg."));
738  else if (__isnan(__a) || __isnan(__b)
739  || __isnan(__c) || __isnan(__x))
740  return std::numeric_limits<_Tp>::quiet_NaN();
741  else if (__c_nint == __c && __c_nint <= _Tp(0))
742  return std::numeric_limits<_Tp>::infinity();
743  else if (std::abs(__c - __b) < __toler || std::abs(__c - __a) < __toler)
744  return std::pow(_Tp(1) - __x, __c - __a - __b);
745  else if (__a >= _Tp(0) && __b >= _Tp(0) && __c >= _Tp(0)
746  && __x >= _Tp(0) && __x < _Tp(0.995L))
747  return __hyperg_series(__a, __b, __c, __x);
748  else if (std::abs(__a) < _Tp(10) && std::abs(__b) < _Tp(10))
749  {
750  // For integer a and b the hypergeometric function is a
751  // finite polynomial.
752  if (__a < _Tp(0) && std::abs(__a - __a_nint) < __toler)
753  return __hyperg_series(__a_nint, __b, __c, __x);
754  else if (__b < _Tp(0) && std::abs(__b - __b_nint) < __toler)
755  return __hyperg_series(__a, __b_nint, __c, __x);
756  else if (__x < -_Tp(0.25L))
757  return __hyperg_luke(__a, __b, __c, __x);
758  else if (__x < _Tp(0.5L))
759  return __hyperg_series(__a, __b, __c, __x);
760  else
761  if (std::abs(__c) > _Tp(10))
762  return __hyperg_series(__a, __b, __c, __x);
763  else
764  return __hyperg_reflect(__a, __b, __c, __x);
765  }
766  else
767  return __hyperg_luke(__a, __b, __c, __x);
768  }
769 
770  _GLIBCXX_END_NAMESPACE_VERSION
771  } // namespace std::tr1::__detail
772 }
773 }
#define __try
Definition: exception_defines.h:35
__inline __m256 float float float float float __F
Definition: avxintrin.h:1189
const _Tp & max(const _Tp &__a, const _Tp &__b)
Equivalent to std::max.
Definition: base.h:150
#define __catch(X)
Definition: exception_defines.h:36
__inline __m256 float float float float __E
Definition: avxintrin.h:1189