| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 namespace math {
8
9 template<typename T>
10 T F32(T a, T b, T c, T d, T e, T z, T precision = 1e-6) {
11 using std::exp;
12 using std::log;
13 using std::fabs;
14
15 T F = 1.0;
16
17 T tNew = 0.0;
18
19 T logT = 0.0;
20
21 T logZ = log(z);
22
23 int k = 0.0;
24
25 while (fabs(tNew) > precision || k == 0) {
26 T p = (a + k) * (b + k) * (c + k) / ( (d + k) * (e + k) * (k + 1) );
27
28 // If a, b, or c is a negative integer then the series terminates
29 // after a finite number of interations
30 if (p == 0) break;
31
32 logT += (p > 0 ? 1.0 : -1.0) * log(fabs(p)) + logZ;
33
34 tNew = exp(logT);
35
36 F += tNew;
37
38 ++k;
39 }
40 return F;
41 }
42
43 }
44 }
45 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
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:94
stan::math::F32
T F32(T a, T b, T c, T d, T e, T z, T precision=1e-6)
Definition: F32.hpp:10

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