You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
template<typename T>
T digamma(T x)
{
T result = 0;
// Check for negative arguments and use reflection
if (x <= -1)
{
// Reflect
x = 1 - x;
// Argument reduction for tan
T reminder = x - floor(x);
// Shift to negative if x > 0.5
if (reminder > 0.5)
reminder -= 1;
// Check for evaluation at negative pole
if (reminder == 0)
{
// throw proper exception
throw std::runtime_error("Evaluation of fucntion at pole");
}
result = M_PI / tan(M_PI * reminder);
}
if (x == 0)
{
// throw exception
throw std::runtime_error("Evaluation of fucntion at pole");
}
// Direct formula to calculate digamma
result += std::log(x) - (1 / (2 * x));
return result;
}