Skip to content

Commit

Permalink
math: correct inline function
Browse files Browse the repository at this point in the history
  • Loading branch information
zzjjzzgggg committed Jul 19, 2017
1 parent 767570b commit a38a5ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 0 additions & 8 deletions math/mathutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@
#include "mathutils.h"
#include <cmath>

double SpecFun::LogBinCoeff(const int k, const int n) {
return std::lgamma(n + 1) - std::lgamma(k + 1) - std::lgamma(n - k + 1);
}

double SpecFun::BinCoeff(const int k, const int n) {
return std::exp(LogBinCoeff(k, n));
}

double SpecFun::LogBetaCoeff(const double alpha, const double beta) {
return std::lgamma(alpha) + std::lgamma(beta) - std::lgamma(alpha + beta);
}

double SpecFun::BetaCoeff(const double alpha, const double beta) {
return std::exp(LogBetaCoeff(alpha, beta));
}
Expand Down
9 changes: 7 additions & 2 deletions math/mathutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class SpecFun {
/**
* log of Binomial coefficient.
*/
inline static double LogBinCoeff(const int k, const int n);
inline static double LogBinCoeff(const int k, const int n) {
return std::lgamma(n + 1) - std::lgamma(k + 1) - std::lgamma(n - k + 1);
}

/**
* Binomial coefficient, i.e., n choose k.
Expand All @@ -27,7 +29,10 @@ class SpecFun {
/**
* log of Beta distribution coefficient
*/
inline static double LogBetaCoeff(const double alpha, const double beta);
inline static double LogBetaCoeff(const double alpha, const double beta) {
return std::lgamma(alpha) + std::lgamma(beta) -
std::lgamma(alpha + beta);
}

/**
* Beta distribution coefficient.
Expand Down

0 comments on commit a38a5ab

Please sign in to comment.