inline double dcdflib_binomial_cdf(double x, double s, double sf) { int what = 1; int status = 0; double p, q, bound, sfc(1-sf); cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound); return p; }
inline double dcdflib_binomial_quantile(double p, double s, double sf) { int what = 2; int status = 0; double x, bound, q(1 - p), sfc(1-sf); cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound); return x; }
void V_cdfbin(int *which, double *p, double *q, double *s, double *xn, double *pr, double *ompr, int *status, double *bound, int *len) { int i; for (i = 0; i < *len; i++) { cdfbin((int *)which, &p[i], &q[i], &s[i], &xn[i], &pr[i], &ompr[i], (int *)&status[i], &bound[i]); } }
static int cdf_pbinom (lua_State *L) { /* stack should contain s, xn, pr */ lua_Number s = luaL_checknumber(L, 1); lua_Number xn = luaL_checknumber(L, 2); lua_Number pr = luaL_checknumber(L, 3); lua_Number p, q, ompr, bound; int which = 1; int status; check_binom(L, 1, s, xn, pr); ompr = 1-pr; cdfbin(&which, &p, &q, &s, &xn, &pr, &ompr, &status, &bound); check_status(status, bound); lua_pushnumber(L, p); return 1; }
static int cdf_qbinom (lua_State *L) { /* stack should contain p, xn, pr */ lua_Number p = luaL_checknumber(L, 1); lua_Number xn = luaL_checknumber(L, 2); lua_Number pr = luaL_checknumber(L, 3); lua_Number s; int si; check_binom(L, 2, p, xn, pr); if (p==0 || p==1) s = p*xn; else { lua_Number q = 1-p; lua_Number ompr = 1-pr; lua_Number bound; int which = 2; int status; cdfbin(&which, &p, &q, &s, &xn, &pr, &ompr, &status, &bound); check_status(status, bound); } lua_number2int(si, s); lua_pushinteger(L, si); return 1; }