static int cdf_dbeta (lua_State *L) { /* stack should contain x, a and b */ lua_Number x = luaL_checknumber(L, 1); lua_Number a = luaL_checknumber(L, 2); lua_Number b = luaL_checknumber(L, 3); check_beta(L, 1, x, a, b); lua_pushnumber(L, (x==0 || x==1) ? 0 : exp((a-1)*log(x)+(b-1)*log(1-x)-dlnbet(&a, &b))); return 1; }
static int cdf_pbeta (lua_State *L) { /* stack should contain x, a and b */ lua_Number x = luaL_checknumber(L, 1); lua_Number a = luaL_checknumber(L, 2); lua_Number b = luaL_checknumber(L, 3); lua_Number p, q, y, bound; int which = 1; int status; check_beta(L, 1, x, a, b); y = 1-x; cdfbet(&which, &p, &q, &x, &y, &a, &b, &status, &bound); check_status(status, bound); lua_pushnumber(L, p); return 1; }
static int cdf_qbeta (lua_State *L) { /* stack should contain x, a and b */ lua_Number p = luaL_checknumber(L, 1); lua_Number a = luaL_checknumber(L, 2); lua_Number b = luaL_checknumber(L, 3); lua_Number x; check_beta(L, 2, p, a, b); if (p==0 || p==1) x = p; else { lua_Number q, y, bound; int which = 2; int status; q = 1-p; cdfbet(&which, &p, &q, &x, &y, &a, &b, &status, &bound); check_status(status, bound); } lua_pushnumber(L, x); return 1; }
inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol) { // Check both alpha and beta. return check_alpha(function, alpha, result, pol) && check_beta(function, beta, result, pol); } // bool check_dist