inline double dcdflib_poisson_quantile(double p, double param) { int what = 2; int status = 0; double x, bound, q(1 - p); cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound); return x; }
inline double dcdflib_poisson_cdf(double x, double param) { int what = 1; int status = 0; double p, q, bound; cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound); return p; }
void V_cdfpoi(int *which, double *p, double *q, double *s, double *xlam, int *status, double *bound, int *len) { int i; for (i = 0; i < *len; i++) { cdfpoi((int *)which, &p[i], &q[i], &s[i], &xlam[i], (int *)&status[i], &bound[i]); } }
static int stat_ppois (lua_State *L) { /* stack should contain s and xlam */ lua_Number s = luaL_checknumber(L, 1); lua_Number xlam = luaL_checknumber(L, 2); lua_Number p, q, bound; int which = 1; int status; check_pois(L, 1, s, xlam); cdfpoi(&which, &p, &q, &s, &xlam, &status, &bound); check_status(L, status, bound); lua_pushnumber(L, p); return 1; }
static int cdf_qpois (lua_State *L) { /* stack should contain p and xlam */ lua_Number p = luaL_checknumber(L, 1); lua_Number xlam = luaL_checknumber(L, 2); int si = 0; check_pois(L, 2, p, xlam); if (p==1) { lua_pushnumber(L, HUGE_VAL); return 1; } if (p>0) { lua_Number q = 1-p; lua_Number s, bound; int which = 2; int status; cdfpoi(&which, &p, &q, &s, &xlam, &status, &bound); check_status(status, bound); lua_number2int(si, s); } lua_pushinteger(L, si); return 1; }