pub mod utils;
pub mod cephes64;
pub mod misc;
pub struct EllipJOutput<T> {
pub sn: T,
pub cn: T,
pub dn: T,
pub phi: T
}
pub struct AiryOutput<T> {
pub ai: T,
pub aip: T,
pub bi: T,
pub bip: T
}
pub struct FresnelOutput<T> {
pub s: T,
pub c: T
}
pub struct SiCiOutput<T> {
pub si: T,
pub ci: T
}
pub struct ShiChiOutput<T> {
pub shi: T,
pub chi: T
}
pub trait Erf {
fn erf(&self) -> Self;
fn erfc(&self) -> Self;
fn erf_inv(&self) -> Self;
fn erfc_inv(&self) -> Self;
}
impl Erf for f64 {
fn erf(&self) -> f64 {
crate::cephes64::erf(*self)
}
fn erfc(&self) -> f64 {
crate::cephes64::erfc(*self)
}
fn erf_inv(&self) -> f64 {
crate::misc::erfinv(*self)
}
fn erfc_inv(&self) -> f64 {
crate::misc::erfcinv(*self)
}
}
pub trait Fresnel: Sized {
fn fresnel(&self) -> FresnelOutput<Self>;
}
impl Fresnel for f64 {
fn fresnel(&self) -> FresnelOutput<f64> {
let res = crate::cephes64::fresnl(*self);
FresnelOutput::<f64> {s: res.0, c: res.1}
}
}
pub trait SiCi: Sized {
fn sici(&self) -> SiCiOutput<Self>;
}
impl SiCi for f64 {
fn sici(&self) -> SiCiOutput<f64> {
let res = crate::cephes64::sici(*self);
SiCiOutput::<f64> {si: res.0, ci: res.1}
}
}
pub trait ShiChi: Sized {
fn shichi(&self) -> ShiChiOutput<Self>;
}
impl ShiChi for f64 {
fn shichi(&self) -> ShiChiOutput<f64> {
let res = crate::cephes64::shichi(*self);
ShiChiOutput::<f64> {shi: res.0, chi: res.1}
}
}
pub trait Expn {
fn expn(&self, n: i32) -> Self;
}
impl Expn for f64 {
fn expn(&self, n: i32) -> f64 {
crate::cephes64::expn(n, *self)
}
}
pub trait Dawson {
fn dawson(&self) -> Self;
}
impl Dawson for f64 {
fn dawson(&self) -> f64 {
crate::cephes64::dawsn(*self)
}
}
pub trait Polylog {
fn li2(&self) -> Self;
}
impl Polylog for f64 {
fn li2(&self) -> f64 {
crate::cephes64::spence(*self)
}
}
pub trait NormDist {
fn norm_pdf(&self) -> Self;
fn norm_cdf(&self) -> Self;
fn norm_cdf_inv(&self) -> Self;
}
impl NormDist for f64 {
fn norm_pdf(&self) -> f64 {
crate::misc::norm_pdf(*self)
}
fn norm_cdf(&self) -> f64 {
crate::cephes64::ndtr(*self)
}
fn norm_cdf_inv(&self) -> f64 {
crate::cephes64::ndtri(*self)
}
}
pub trait TDist {
fn t_pdf(&self, df: Self) -> Self;
fn t_cdf(&self, df: isize) -> Self;
fn t_cdf_inv(&self, df: isize) -> Self;
}
impl TDist for f64 {
fn t_pdf(&self, df: f64) -> f64 {
crate::misc::t_pdf(df, *self)
}
fn t_cdf(&self, df: isize) -> f64 {
crate::cephes64::stdtr(df, *self)
}
fn t_cdf_inv(&self, df: isize) -> f64 {
crate::cephes64::stdtri(df, *self)
}
}
pub trait BinomDist {
fn binom_pmf(&self, k: f64, n: isize) -> Self;
fn binom_cdf(&self, k: Self, n: isize) -> Self;
fn binom_cdfc(&self, k: Self, n: isize) -> Self;
fn binom_cdf_inv(&self, k: Self, n: isize) -> Self;
}
impl BinomDist for f64 {
fn binom_pmf(&self, k: f64, n: isize) -> f64 {
crate::misc::binom_pmf(k, n as i32, *self)
}
fn binom_cdf(&self, k: f64, n: isize) -> f64 {
crate::cephes64::bdtr(k, n, *self)
}
fn binom_cdfc(&self, k: f64, n: isize) -> f64 {
crate::cephes64::bdtrc(k, n, *self)
}
fn binom_cdf_inv(&self, k: Self, n: isize) -> f64 {
crate::cephes64::bdtri(k, n, *self)
}
}
pub trait NBinomDist {
fn nbinom_pmf(&self, k: isize, n: isize) -> Self;
fn nbinom_cdf(&self, k: isize, n: isize) -> Self;
fn nbinom_cdfc(&self, k: isize, n: isize) -> Self;
fn nbinom_cdf_inv(&self, k: isize, n: isize) -> Self;
}
impl NBinomDist for f64 {
fn nbinom_pmf(&self, k: isize, n: isize) -> f64 {
crate::misc::nbinom_pmf(k as i32, n as i32, *self)
}
fn nbinom_cdf(&self, k: isize, n: isize) -> f64 {
crate::cephes64::nbdtr(k, n, *self)
}
fn nbinom_cdfc(&self, k: isize, n: isize) -> f64 {
crate::cephes64::nbdtrc(k, n, *self)
}
fn nbinom_cdf_inv(&self, k: isize, n: isize) -> f64 {
crate::cephes64::nbdtri(k, n, *self)
}
}
pub trait Gamma {
fn gamma(&self) -> Self;
fn lgamma(&self) -> Self;
fn igamma(&self, x: Self) -> Self;
fn igammac(&self, x: Self) -> Self;
fn igamma_inv(&self, x: Self) -> Self;
fn igammac_inv(&self, x: Self) -> Self;
fn digamma(&self) -> Self;
fn rgamma(&self) -> Self;
fn poch(&self, n: Self) -> Self;
}
impl Gamma for f64 {
fn gamma(&self) -> f64 {
crate::cephes64::gamma(*self)
}
fn lgamma(&self) -> f64 {
crate::cephes64::lgam(*self)
}
fn igamma(&self, x: f64) -> f64 {
crate::cephes64::igam(*self, x)
}
fn igammac(&self, x: f64) -> f64 {
crate::cephes64::igamc(*self, x)
}
fn igamma_inv(&self, x: f64) -> f64 {
crate::cephes64::igami(*self, x)
}
fn igammac_inv(&self, x: f64) -> f64 {
crate::cephes64::igamci(*self, x)
}
fn digamma(&self) -> f64 {
crate::cephes64::psi(*self)
}
fn rgamma(&self) -> f64 {
crate::cephes64::rgamma(*self)
}
fn poch(&self, n: f64) -> f64 {
crate::misc::poch(*self, n)
}
}
pub trait Beta {
fn beta(&self, other: Self) -> Self;
fn lbeta(&self, other: Self) -> Self;
fn ibeta(&self, a: Self, b: Self) -> Self;
fn ibeta_inv(&self, a: Self, b: Self) -> Self;
}
impl Beta for f64 {
fn beta(&self, other: f64) -> f64 {
crate::cephes64::beta(*self, other)
}
fn lbeta(&self, other: f64) -> f64 {
crate::cephes64::lbeta(*self, other)
}
fn ibeta(&self, a: f64, b: f64) -> f64 {
crate::cephes64::incbet(a, b, *self)
}
fn ibeta_inv(&self, a: f64, b: f64) -> f64 {
crate::cephes64::incbi(a, b, *self)
}
}
pub trait BetaDist {
fn beta_pdf(&self, a: Self, b: Self) -> Self;
fn beta_cdf(&self, a: Self, b: Self) -> Self;
fn beta_cdf_inv(&self, a: Self, b: Self) -> Self;
}
impl BetaDist for f64 {
fn beta_pdf(&self, a: f64, b: f64) -> f64 {
crate::misc::beta_pdf(a, b, *self)
}
fn beta_cdf(&self, a: f64, b: f64) -> f64 {
crate::cephes64::btdtr(a,b, *self)
}
fn beta_cdf_inv(&self, a: f64, b: f64) -> f64 {
crate::cephes64::incbi(a, b, *self)
}
}
pub trait Chi2Dist {
fn chi2_pdf(&self, df: Self) -> Self;
fn chi2_cdf(&self, df: Self) -> Self;
fn chi2_cdfc(&self, df: Self) -> Self;
fn chi2_cdf_inv(&self, df: Self) -> Self;
}
impl Chi2Dist for f64 {
fn chi2_pdf(&self, df: f64) -> f64 {
crate::misc::chi2_pdf(df, *self)
}
fn chi2_cdf(&self, df: f64) -> f64 {
crate::cephes64::chdtr(df, *self)
}
fn chi2_cdfc(&self, df: f64) -> f64 {
crate::cephes64::chdtrc(df, *self)
}
fn chi2_cdf_inv(&self, df: f64) -> f64 {
crate::cephes64::chdtri(df, *self)
}
}
pub trait PoissonDist {
fn pois_pmf(&self, k: i32) -> Self;
fn pois_cdf(&self, k: Self) -> Self;
fn pois_cdfc(&self, k: Self) -> Self;
fn pois_cdf_inv(&self, k: isize) -> Self;
}
impl PoissonDist for f64 {
fn pois_pmf(&self, k: i32) -> f64 {
crate::misc::pois_pmf(k, *self)
}
fn pois_cdf(&self, k: f64) -> f64 {
crate::cephes64::pdtr(k, *self)
}
fn pois_cdfc(&self, k: f64) -> f64 {
crate::cephes64::pdtrc(k, *self)
}
fn pois_cdf_inv(&self, k: isize) -> f64 {
crate::cephes64::pdtri(k, *self)
}
}
pub trait FDist {
fn f_pdf(&self, a: Self, b: Self) -> Self;
fn f_cdf(&self, a: Self, b: Self) -> Self;
fn f_cdfc(&self, a: Self, b: Self) -> Self;
fn f_cdf_inv(&self, a: Self, b: Self) -> Self;
}
impl FDist for f64 {
fn f_pdf(&self, a: f64, b: f64) -> f64 {
crate::misc::f_pdf(a, b, *self)
}
fn f_cdf(&self, a: f64, b: f64) -> f64 {
crate::cephes64::fdtr(a,b, *self)
}
fn f_cdfc(&self, a: f64, b: f64) -> f64 {
crate::cephes64::fdtrc(a,b, *self)
}
fn f_cdf_inv(&self, a: f64, b: f64) -> f64 {
crate::cephes64::fdtri(a, b, *self)
}
}
pub trait GammaDist {
fn gamma_pdf(&self, a: Self, b: Self) -> Self;
fn gamma_cdf(&self, a: Self, b: Self) -> Self;
fn gamma_cdfc(&self, a: Self, b: Self) -> Self;
fn gamma_cdf_inv(&self, a: Self, b: Self) -> Self;
}
impl GammaDist for f64 {
fn gamma_pdf(&self, a: f64, b: f64) -> f64 {
crate::misc::gamma_pdf(a, b, *self)
}
fn gamma_cdf(&self, a: f64, b: f64) -> f64 {
crate::cephes64::gdtr(a,b, *self)
}
fn gamma_cdfc(&self, a: f64, b: f64) -> f64 {
crate::cephes64::gdtrc(a,b, *self)
}
fn gamma_cdf_inv(&self, a: f64, b: f64) -> f64 {
crate::cephes64::gdtri(a, b, *self)
}
}
pub trait Zeta {
fn zeta(&self) -> Self;
fn zetac(&self) -> Self;
fn hzeta(&self, q: Self) -> Self;
}
impl Zeta for f64 {
fn zeta(&self) -> f64 {
crate::cephes64::riemann_zeta(*self)
}
fn zetac(&self) -> f64 {
crate::cephes64::zetac(*self)
}
fn hzeta(&self, q: f64) -> f64 {
crate::cephes64::zeta(*self, q)
}
}
pub trait Ellip: Sized {
fn ellip_j(&self, m: Self) -> EllipJOutput<Self>;
fn ellip_e(&self) -> Self;
fn ellip_k(&self) -> Self;
fn ellip_pi(&self, n: Self) -> Self;
fn ellip_e_inc(&self, phi: Self) -> Self;
fn ellip_k_inc(&self, phi: Self) -> Self;
fn ellip_pi_inc(&self, phi: Self, n: Self) -> Self;
fn carlson_rc(&self, y: Self) -> Self;
fn carlson_rd(&self, y: Self, z: Self) -> Self;
fn carlson_rf(&self, y: Self, z: Self) -> Self;
fn carlson_rg(&self, y: Self, z: Self) -> Self;
fn carlson_rj(&self, y: Self, z: Self, p: Self) -> Self;
}
impl Ellip for f64 {
fn ellip_j(&self, m: f64) -> EllipJOutput<f64> {
let res = crate::cephes64::ellpj(*self, m);
EllipJOutput::<f64> {sn: res.0, cn: res.1, dn: res.2, phi: res.3}
}
fn ellip_e(&self) -> f64 {
crate::cephes64::ellpe(*self)
}
fn ellip_k(&self) -> f64 {
crate::cephes64::ellpk(1.0 - *self)
}
fn ellip_pi(&self, n: f64) -> f64 {
crate::misc::ellippi(n, *self)
}
fn ellip_e_inc(&self, phi: f64) -> f64 {
crate::cephes64::ellie(phi, *self)
}
fn ellip_k_inc(&self, phi: f64) -> f64 {
crate::cephes64::ellik(phi, *self)
}
fn ellip_pi_inc(&self, phi: f64, n: f64) -> f64 {
crate::misc::ellippi_inc(phi, *self, n)
}
fn carlson_rc(&self, y: f64) -> f64 {
crate::misc::elliprc(*self, y)
}
fn carlson_rd(&self, y: f64, z: f64) -> f64 {
crate::misc::elliprd(*self, y, z)
}
fn carlson_rf(&self, y: f64, z: f64) -> f64 {
crate::misc::elliprf(*self, y, z)
}
fn carlson_rg(&self, y: f64, z: f64) -> f64 {
crate::misc::elliprg(*self, y, z)
}
fn carlson_rj(&self, y: f64, z: f64, p: f64) -> f64 {
crate::misc::elliprj(*self, y, z, p)
}
}
pub trait Bessel: Sized {
fn airy(&self) -> AiryOutput<Self>;
fn bessel_j0(&self) -> Self;
fn bessel_y0(&self) -> Self;
fn bessel_i0(&self) -> Self;
fn bessel_i0e(&self) -> Self;
fn bessel_j1(&self) -> Self;
fn bessel_y1(&self) -> Self;
fn bessel_i1(&self) -> Self;
fn bessel_i1e(&self) -> Self;
fn bessel_k0(&self) -> Self;
fn bessel_k0e(&self) -> Self;
fn bessel_k1(&self) -> Self;
fn bessel_k1e(&self) -> Self;
fn bessel_yn(&self, n: isize) -> Self;
fn bessel_kn(&self, n: isize) -> Self;
fn bessel_jv(&self, v: f64) -> Self;
fn bessel_yv(&self, v: f64) -> Self;
fn bessel_poly(&self, lambda: Self, nu: Self) -> Self;
}
impl Bessel for f64 {
fn airy(&self) -> AiryOutput<f64> {
let res = crate::cephes64::airy(*self);
AiryOutput::<f64> {ai: res.0, aip: res.1, bi: res.2, bip: res.3}
}
fn bessel_j0(&self) -> f64 {
crate::cephes64::j0(*self)
}
fn bessel_y0(&self) -> f64 {
crate::cephes64::y0(*self)
}
fn bessel_i0(&self) -> f64 {
crate::cephes64::i0(*self)
}
fn bessel_i0e(&self) -> f64 {
crate::cephes64::i0e(*self)
}
fn bessel_j1(&self) -> f64 {
crate::cephes64::j1(*self)
}
fn bessel_y1(&self) -> f64 {
crate::cephes64::y1(*self)
}
fn bessel_i1(&self) -> f64 {
crate::cephes64::i1(*self)
}
fn bessel_i1e(&self) -> f64 {
crate::cephes64::i1e(*self)
}
fn bessel_k0(&self) -> f64 {
crate::cephes64::k0(*self)
}
fn bessel_k0e(&self) -> f64 {
crate::cephes64::k0e(*self)
}
fn bessel_k1(&self) -> f64 {
crate::cephes64::k1(*self)
}
fn bessel_k1e(&self) -> f64 {
crate::cephes64::k1e(*self)
}
fn bessel_yn(&self, n: isize) -> f64 {
crate::cephes64::yn(n, *self)
}
fn bessel_kn(&self, n: isize) -> f64 {
crate::cephes64::kn(n, *self)
}
fn bessel_jv(&self, v: f64) -> f64 {
crate::cephes64::jv(v, *self)
}
fn bessel_yv(&self, v: f64) -> f64 {
crate::cephes64::yv(v, *self)
}
fn bessel_poly(&self, lambda: f64, nu: f64) -> f64 {
crate::misc::besselpoly(*self, lambda, nu)
}
}