Skip to main content

Module rmath

Module rmath 

Source
Expand description

Rmath — Statistical distribution functions and special math functions.

Implements the R C API mathematical functions declared in Rmath.h. These are extern "C" functions resolved by package .so files at load time.

Core special functions:

  • Regularized incomplete gamma function (lower P and upper Q)
  • Regularized incomplete beta function
  • Polygamma functions (digamma, trigamma, etc.)

Distribution functions follow R’s convention:

  • d*(x, params..., give_log) — density (PDF), optionally log
  • p*(x, params..., lower_tail, log_p) — distribution (CDF)
  • q*(p, params..., lower_tail, log_p) — quantile (inverse CDF)
  • r*(params...) — random variate

Constants§

DBL_EPSILON 🔒
LN_SQRT_2PI 🔒

Functions§

Rf_bessel_i
Rf_bessel_i_ex
Rf_bessel_j
Rf_bessel_j_ex
Rf_bessel_k
Rf_bessel_k_ex
Rf_bessel_y
Rf_bessel_y_ex
Rf_dbeta
Rf_dbinom
Rf_dcauchy
Rf_dchisq
Rf_dexp
Rf_df
Rf_dgamma
Rf_dgeom
Rf_dhyper
Rf_dlnorm
Rf_dlogis
Rf_dnbeta
Rf_dnbinom
Rf_dnbinom_mu
Rf_dnchisq
Rf_dnf
Rf_dnorm4
Rf_dnt
Rf_dpois
Rf_dsignrank
Rf_dt
Rf_dunif
Rf_dweibull
Rf_dwilcox
Rf_hypot
Rf_pbeta
Rf_pbinom
Rf_pcauchy
Rf_pchisq
Rf_pexp
Rf_pf
Rf_pgamma
Rf_pgeom
Rf_phyper
Rf_plnorm
Rf_plogis
Rf_pnbeta
Rf_pnbinom
Rf_pnbinom_mu
Rf_pnchisq
Rf_pnf
Rf_pnorm5
Rf_pnorm_both
Rf_pnt
Rf_ppois
Rf_psignrank
Rf_pt
Rf_ptukey
Rf_punif
Rf_pweibull
Rf_pwilcox
Rf_qbeta
Rf_qbinom
Rf_qcauchy
Rf_qchisq
Rf_qexp
Rf_qf
Rf_qgamma
Rf_qgeom
Rf_qhyper
Rf_qlnorm
Rf_qlogis
Rf_qnbeta
Rf_qnbinom
Rf_qnbinom_mu
Rf_qnchisq
Rf_qnf
Rf_qnorm5
Rf_qnt
Rf_qpois
Rf_qsignrank
Rf_qt
Rf_qtukey
Rf_qunif
Rf_qweibull
Rf_qwilcox
Rf_rbeta
Rf_rbinom
Rf_rcauchy
Rf_rchisq
Rf_rexp
Rf_rf
Rf_rgamma
Rf_rgeom
Rf_rhyper
Rf_rlnorm
Rf_rlogis
Rf_rnbinom
Rf_rnchisq
Rf_rnorm
Rf_rpois
Rf_rsignrank
Rf_rt
Rf_runif
Rf_rweibull
Rf_rwilcox
bessel_i_series 🔒
bessel_j_series 🔒
bessel_k0 🔒
bessel_k1 🔒
bessel_k_int 🔒
beta_cf_term 🔒
Terms for the continued fraction expansion of the incomplete beta function.
beta_fn
Beta function B(a,b) = Γ(a)Γ(b)/Γ(a+b).
choose_fn
Binomial coefficient choose(n, k).
d_log 🔒
Apply give_log to a density value.
digamma_fn
Digamma function ψ(x) = d/dx ln Γ(x).
gamma_cf 🔒
Continued fraction for the upper incomplete gamma function.
gamma_series 🔒
Series expansion for the regularized incomplete gamma function.
lbeta_fn
Log-beta function ln B(a,b).
lchoose_fn
Log of binomial coefficient.
lgamma1p_fn
lgamma(1+a) for small a, using series expansion.
log1pmx_fn
log(1+x) - x, accurate for small x.
logspace_add_fn
log(exp(lx) + exp(ly)), computed in log-space for numerical stability.
logspace_sub_fn
log(exp(lx) - exp(ly)), computed in log-space. Requires lx >= ly.
p_transform 🔒
Apply lower_tail and log_p transforms to a CDF value.
pbeta_raw
Regularized incomplete beta function I_x(a, b). Uses continued fraction (Lentz’s method).
pentagamma
Pentagamma function ψ₃(x).
pgamma_raw
Regularized lower incomplete gamma function P(a, x) = γ(a,x) / Γ(a). Uses series expansion for x < a+1, continued fraction otherwise.
psigamma_fn
Psigamma: the m-th derivative of the digamma function.
q_decode 🔒
Decode p from log_p / lower_tail for quantile functions.
qgamma_raw
Regularized upper incomplete gamma function Q(a, x) = 1 - P(a, x).
qnorm_standard 🔒
Standard normal quantile function (inverse Φ).
r_finite 🔒
rmultinom
tetragamma
Tetragamma function ψ₂(x).
trigamma
Trigamma function ψ₁(x) = d²/dx² ln Γ(x).
unif_rand 🔒
Call the thread-local RNG from runtime.rs