All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
binomial_coefficient_log.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_FUN_BINOMIAL_COEFFICIENT_LOG_HPP
#define STAN_MATH_PRIM_SCAL_FUN_BINOMIAL_COEFFICIENT_LOG_HPP
#include <boost/math/special_functions/gamma.hpp>
#include <boost/math/tools/promotion.hpp>
namespace stan {
namespace math {
template <typename T_N, typename T_n>
inline typename boost::math::tools::promote_args<T_N, T_n>::type
binomial_coefficient_log(const T_N N, const T_n n) {
using std::log;
using boost::math::lgamma;
const double cutoff = 1000;
if ((N < cutoff) || (N - n < cutoff)) {
return lgamma(N + 1.0) - lgamma(n + 1.0) - lgamma(N - n + 1.0);
} else {
return n * log(N - n) + (N + 0.5) * log(N/(N-n))
+ 1/(12*N) - n - 1/(12*(N-n)) - lgamma(n + 1.0);
}
}
}
}
#endif
stan::math::binomial_coefficient_log
fvar< T > binomial_coefficient_log(const fvar< T > &x1, const fvar< T > &x2)
Definition: binomial_coefficient_log.hpp:16
stan::math::lgamma
fvar< T > lgamma(const fvar< T > &x)
Definition: lgamma.hpp:15
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15

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