# Chapter 31 R Math Library

R Math Library is a library that provides functions such as math and statistics defined by R. These functions become available when you include `Rmath.h`. Since Rmath itself is an independent library, it can be used from other programs. You can also call the function defined in `Rmath.h` from Rcpp. They are defined in the `R::` namespace.

The function of `Rmath.h` is written in C language and it is not vectorized.

``````double R::norm_rand(void)
double R::unif_rand(void)
double R::exp_rand(void)

void R::pnorm_both(double x, double *cum, double *ccum, int lt, int lg)
void R::rmultinom(int n, double* prob, int k, int* rn)

double R::dsignrank(double x, double n, int lg)
double R::psignrank(double x, double n, int lt, int lg)
double R::qsignrank(double x, double n, int lt, int lg)
double R::rsignrank(double n)

double R::dwilcox(double x, double m, double n, int lg)
double R::pwilcox(double q, double m, double n, int lt, int lg)
double R::qwilcox(double x, double m, double n, int lt, int lg)
double R::rwilcox(double m, double n)

double R::ptukey(double q, double rr, double cc, double df, int lt, int lg)
double R::qtukey(double p, double rr, double cc, double df, int lt, int lg)

double R::log1pmx(double x)
double R::log1pexp(double x)
double R::lgamma1p(double a)

double R::logspace_add(double lx, double ly)
double R::logspace_sub(double lx, double ly)

double R::gammafn(double x)
double R::lgammafn(double x)
double R::lgammafn_sign(double x, int *sgn)

void   R::dpsifn(double x, int n, int kode, int m, double *ans, int *nz, int *ierr)
double R::psigamma(double x, double deriv)
double R::digamma(double x)
double R::trigamma(double x)
double R::tetragamma(double x)
double R::pentagamma(double x)

double R::beta(double a, double b)
double R::lbeta(double a, double b)

double R::choose(double n, double k)
double R::lchoose(double n, double k)

double R::bessel_i(double x, double al, double ex)
double R::bessel_j(double x, double al)
double R::bessel_k(double x, double al, double ex)
double R::bessel_y(double x, double al)
double R::bessel_i_ex(double x, double al, double ex, double *bi)
double R::bessel_j_ex(double x, double al, double *bj)
double R::bessel_k_ex(double x, double al, double ex, double *bk)
double R::bessel_y_ex(double x, double al, double *by)

double R::hypot(double a, double b)
double R::pythag(double a, double b)

double R::expm1(double x); /* = exp(x)-1 {care for small x} */
double R::log1p(double x); /* = log(1+x) {care for small x} */

int R::imax2(int x, int y)
int R::imin2(int x, int y)

double R::fmax2(double x, double y)
double R::fmin2(double x, double y)

double R::sign(double x)

double R::fprec(double x, double dg)
double R::fround(double x, double dg)
double R::fsign(double x, double y)
double R::ftrunc(double x)      ``````

The probability distribution function is also described on the page Probability distributions.

``````double R::dnorm(double x, double mu, double sigma, int lg)
double R::pnorm(double x, double mu, double sigma, int lt, int lg)
double R::qnorm(double p, double mu, double sigma, int lt, int lg)
double R::rnorm(double mu, double sigma)

double R::dunif(double x, double a, double b, int lg)
double R::punif(double x, double a, double b, int lt, int lg)
double R::qunif(double p, double a, double b, int lt, int lg)
double R::runif(double a, double b)

double R::dgamma(double x, double shp, double scl, int lg)
double R::pgamma(double x, double alp, double scl, int lt, int lg)
double R::qgamma(double p, double alp, double scl, int lt, int lg)
double R::rgamma(double a, double scl)

double R::dbeta(double x, double a, double b, int lg)
double R::pbeta(double x, double p, double q, int lt, int lg)
double R::qbeta(double a, double p, double q, int lt, int lg)
double R::rbeta(double a, double b)

double R::dlnorm(double x, double ml, double sl, int lg)
double R::plnorm(double x, double ml, double sl, int lt, int lg)
double R::qlnorm(double p, double ml, double sl, int lt, int lg)
double R::rlnorm(double ml, double sl)

double R::dchisq(double x, double df, int lg)
double R::pchisq(double x, double df, int lt, int lg)
double R::qchisq(double p, double df, int lt, int lg)
double R::rchisq(double df)

double R::dnchisq(double x, double df, double ncp, int lg)
double R::pnchisq(double x, double df, double ncp, int lt, int lg)
double R::qnchisq(double p, double df, double ncp, int lt, int lg)
double R::rnchisq(double df, double lb)

double R::df(double x, double df1, double df2, int lg)
double R::pf(double x, double df1, double df2, int lt, int lg)
double R::qf(double p, double df1, double df2, int lt, int lg)
double R::rf(double df1, double df2)

double R::dt(double x, double n, int lg)
double R::pt(double x, double n, int lt, int lg)
double R::qt(double p, double n, int lt, int lg)
double R::rt(double n)

double R::dbinom(double x, double n, double p, int lg)
double R::pbinom(double x, double n, double p, int lt, int lg)
double R::qbinom(double p, double n, double m, int lt, int lg)
double R::rbinom(double n, double p)

double R::dcauchy(double x, double lc, double sl, int lg)
double R::pcauchy(double x, double lc, double sl, int lt, int lg)
double R::qcauchy(double p, double lc, double sl, int lt, int lg)
double R::rcauchy(double lc, double sl)

double R::dexp(double x, double sl, int lg)
double R::pexp(double x, double sl, int lt, int lg)
double R::qexp(double p, double sl, int lt, int lg)
double R::rexp(double sl)

double R::dgeom(double x, double p, int lg)
double R::pgeom(double x, double p, int lt, int lg)
double R::qgeom(double p, double pb, int lt, int lg)
double R::rgeom(double p)

double R::dhyper(double x, double r, double b, double n, int lg)
double R::phyper(double x, double r, double b, double n, int lt, int lg)
double R::qhyper(double p, double r, double b, double n, int lt, int lg)
double R::rhyper(double r, double b, double n)

double R::dnbinom(double x, double sz, double pb, int lg)
double R::pnbinom(double x, double sz, double pb, int lt, int lg)
double R::qnbinom(double p, double sz, double pb, int lt, int lg)
double R::rnbinom(double sz, double pb)

double R::dnbinom_mu(double x, double sz, double mu, int lg)
double R::pnbinom_mu(double x, double sz, double mu, int lt, int lg)
double R::qnbinom_mu(double x, double sz, double mu, int lt, int lg)
double R::rnbinom_mu(double sz, double mu)

double R::dpois(double x, double lb, int lg)
double R::ppois(double x, double lb, int lt, int lg)
double R::qpois(double p, double lb, int lt, int lg)
double R::rpois(double mu)

double R::dlogis(double x, double lc, double sl, int lg)
double R::plogis(double x, double lc, double sl, int lt, int lg)
double R::qlogis(double p, double lc, double sl, int lt, int lg)
double R::rlogis(double lc, double sl)

double R::dnbeta(double x, double a, double b, double ncp, int lg)
double R::pnbeta(double x, double a, double b, double ncp, int lt, int lg)
double R::qnbeta(double p, double a, double b, double ncp, int lt, int lg)
double R::rnbeta(double a, double b, double np)

double R::dnf(double x, double df1, double df2, double ncp, int lg)
double R::pnf(double x, double df1, double df2, double ncp, int lt, int lg)
double R::qnf(double p, double df1, double df2, double ncp, int lt, int lg)

double R::dnt(double x, double df, double ncp, int lg)
double R::pnt(double x, double df, double ncp, int lt, int lg)
double R::qnt(double p, double df, double ncp, int lt, int lg)

double R::dweibull(double x, double sh, double sl, int lg)
double R::pweibull(double x, double sh, double sl, int lt, int lg)
double R::qweibull(double p, double sh, double sl, int lt, int lg)
double R::rweibull(double sh, double sl)``````