Stan Math Library  2.15.0
reverse mode automatic differentiation
choose.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_CHOOSE_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_CHOOSE_HPP
3 
6 #include <boost/math/special_functions/binomial.hpp>
7 #include <limits>
8 
9 namespace stan {
10  namespace math {
11 
27  inline int choose(int n, int k) {
30  check_nonnegative("choose", "n", n);
31  check_nonnegative("choose", "k", k);
32  if (k > n) return 0;
33  const double choices = boost::math::binomial_coefficient<double>(n, k);
34  check_less_or_equal("choose", "n choose k", choices,
36  // won't get proper round until C++11
37  return static_cast<int>(choices < 0 ? choices - 0.5 : choices + 0.5);
38  }
39 
40  }
41 }
42 #endif
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is less or equal to high.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
int choose(int n, int k)
Return the binomial coefficient for the specified integer arguments.
Definition: choose.hpp:27
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:22

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