| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
F32.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_F32_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_F32_HPP
3
4 #include <cmath>
5
6 namespace stan {
7
8 namespace math {
9
10 template<typename T>
11 T F32(T a, T b, T c, T d, T e, T z, T precision = 1e-6) {
12 using std::exp;
13 using std::log;
14 using std::fabs;
15
16 T F = 1.0;
17
18 T tNew = 0.0;
19
20 T logT = 0.0;
21
22 T logZ = log(z);
23
24 int k = 0.0;
25
26 while (fabs(tNew) > precision || k == 0) {
27 T p = (a + k) * (b + k) * (c + k) / ( (d + k) * (e + k) * (k + 1) );
28
29 // If a, b, or c is a negative integer then the series terminates
30 // after a finite number of interations
31 if (p == 0) break;
32
33 logT += (p > 0 ? 1.0 : -1.0) * log(fabs(p)) + logZ;
34
35 tNew = exp(logT);
36
37 F += tNew;
38
39 ++k;
40 }
41 return F;
42 }
43
44 }
45 }
46 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
stan::math::e
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:95
stan::math::F32
T F32(T a, T b, T c, T d, T e, T z, T precision=1e-6)
Definition: F32.hpp:11

[ Stan Home Page ] © 2011–2015, Stan Development Team.