# node-cephes This is a WebAssembly packaging of the [cephes library](http://www.netlib.org/cephes/). The cephes library contains C implementations of most [special functions](https://en.wikipedia.org/wiki/Special_functions), [distributions](https://en.wikipedia.org/wiki/Probability_distribution), and other hard-to-implement mathematical functions. _Note that there are a few cephes functions that are not exposed here, as some of them are quite hard to make consumable in JavaScript using WebAssembly. Feel free to send a pull request if you need one of them._ ## Install ``` npm install cephes ``` If you are looking on GitHub, you will notice some files are missing. These are statically built from the cephes library. See the [CONTRIBUTING.md](CONTRIBUTING.md) file, for how to build them. ## Usage Cephes is a WebAssembly module but is very small and fast to compile, as it doesn't depend on any runtime libraries. In Node.js it is therefore compiled synchronously and all you need to do is require the module. ```js const cephes = require('cephes'); // Node.js ``` In the browser, it is, for good practice, compiled asynchronously. You must therefore wait for the `.compiled` promise to be resolved. ```js const cephes = require('cephes'); // Browser await cephes.compiled; ``` Note that the `.compiled` promise is also available in Node.js, but it is simply a dummy promise that resolves immediately. ### The JavaScript interface There are three variations of functions to be aware of: #### 1. Plain numeric function These don't require anything special. ```js const value = cephes.zeta(2, 1); ``` #### 2. Functions that return more than one value In C, these functions return a primary value and then return extra value using pointer arguments. In JavaScript this is implemented as a function that returns an array of length 2. The first element is the primary returned value, the second is an object of the extra returned values. ```js const [value, {ai, aip, bi, bip}] = cephes.airy(-1); ``` #### 3. Functions that consumes an array Some functions consumes an array of values, these must be `TypedArrays` of the appropriate type. These functions will typically also require a variation of `.length` value as a parameter, like you would do in C. Be aware, that in some cases it may not be exactly the `.length` of the `TypedArray`, but may be one less or one more. Check the specific function documentation to be sure. ```js const arrayInput = new Float64Array([2.2, 3.3, 4.4]); const value = ephes.polevl(1.1, arrayInput, arrayInput.length - 1); ``` ## Table of Content
Function | Description | Documentation |
---|---|---|
Arithmetic and Algebraic | ||
signbit(x) |
Returns the sign bit | c-doc • js-doc |
isnan(x) |
Check if Not-A-Number | c-doc • js-doc |
isfinite(x) |
Check if finite | c-doc • js-doc |
cbrt(x) |
Cube root | c-doc • js-doc |
polevl(x, coef, N) |
Evaluate polynomial | c-doc • js-doc |
chbevl(x, array, n) |
Evaluate Chebyshev series | c-doc • js-doc |
round(x) |
Round to nearest integer value | c-doc • js-doc |
frexp(x) |
Extract exponent | c-doc • js-doc |
ldexp(x, pw2) |
Add integer to exponent | c-doc • js-doc |
Exponential and Trigonometric | ||
expx2(x, sign) |
Exponential of squared argument | c-doc • js-doc |
radian(d, m, s) |
Degrees, minutes, seconds to radians | c-doc • js-doc |
sincos(x, flg) |
Circular sine and cosine of argument in degrees | c-doc • js-doc |
cot(x) |
Circular cotangent | c-doc • js-doc |
cotdg(x) |
Circular cotangent of argument in degrees | c-doc • js-doc |
log1p(x) |
Relative error approximations for log(1 + x) | c-doc • js-doc |
expm1(x) |
Relative error approximations for exp(x) - 1 | c-doc • js-doc |
cosm1(x) |
Relative error approximations for cos(x) - 1 | c-doc • js-doc |
acos(x) |
Arc cosine | c-doc • js-doc |
acosh(x) |
Arc hyperbolic cosine | c-doc • js-doc |
asinh(xx) |
Arc hyperbolic sine | c-doc • js-doc |
atanh(x) |
Arc hyperbolic tangent | c-doc • js-doc |
asin(x) |
Arcsine | c-doc • js-doc |
atan(x) |
Arctangent | c-doc • js-doc |
atan2(y, x) |
Quadrant correct arctangent | c-doc • js-doc |
cos(x) |
Cosine | c-doc • js-doc |
cosdg(x) |
Cosine of arg in degrees | c-doc • js-doc |
exp(x) |
Exponential, base e | c-doc • js-doc |
exp2(x) |
Exponential, base 2 | c-doc • js-doc |
exp10(x) |
Exponential, base 10 | c-doc • js-doc |
cosh(x) |
Hyperbolic cosine | c-doc • js-doc |
sinh(x) |
Hyperbolic sine | c-doc • js-doc |
tanh(x) |
Hyperbolic tangent | c-doc • js-doc |
log(x) |
Logarithm, base e | c-doc • js-doc |
log2(x) |
Logarithm, base 2 | c-doc • js-doc |
log10(x) |
Logarithm, base 10 | c-doc • js-doc |
pow(x, y) |
Power | c-doc • js-doc |
powi(x, nn) |
Integer Power | c-doc • js-doc |
sin(x) |
Sine | c-doc • js-doc |
sindg(x) |
Sine of arg in degrees | c-doc • js-doc |
tan(x) |
Tangent | c-doc • js-doc |
tandg(x) |
Tangent of arg in degrees | c-doc • js-doc |
Exponential integral | ||
ei(x) |
Exponential integral | c-doc • js-doc |
expn(n, x) |
Exponential integral | c-doc • js-doc |
shichi(x) |
Hyperbolic cosine integral | c-doc • js-doc |
sici(x) |
Cosine integral | c-doc • js-doc |
Gamma | ||
lbeta(a, b) |
Natural log of |beta|. | c-doc • js-doc |
beta(a, b) |
Beta | c-doc • js-doc |
fac(i) |
Factorial | c-doc • js-doc |
gamma(x) |
Gamma | c-doc • js-doc |
lgam(x) |
Logarithm of gamma function | c-doc • js-doc |
incbet(aa, bb, xx) |
Incomplete beta integral | c-doc • js-doc |
incbi(aa, bb, yy0) |
Inverse beta integral | c-doc • js-doc |
igam(a, x) |
Incomplete gamma integral | c-doc • js-doc |
igamc(a, x) |
Complemented gamma integral | c-doc • js-doc |
igami(a, y0) |
Inverse gamma integral | c-doc • js-doc |
psi(x) |
Psi (digamma) function | c-doc • js-doc |
rgamma(x) |
Reciprocal Gamma | c-doc • js-doc |
Error function | ||
erf(x) |
Error function | c-doc • js-doc |
erfc(a) |
Complemented error function | c-doc • js-doc |
dawsn(xx) |
Dawson's integral | c-doc • js-doc |
fresnl(xxa) |
Fresnel integral | c-doc • js-doc |
Bessel | ||
airy(x) |
Airy | c-doc • js-doc |
j0(x) |
Bessel, order 0 | c-doc • js-doc |
j1(x) |
Bessel, order 1 | c-doc • js-doc |
jn(n, x) |
Bessel, order n | c-doc • js-doc |
jv(n, x) |
Bessel, noninteger order | c-doc • js-doc |
y0(x) |
Bessel, second kind, order 0 | c-doc • js-doc |
y1(x) |
Bessel, second kind, order 1 | c-doc • js-doc |
yn(n, x) |
Bessel, second kind, order n | c-doc • js-doc |
yv(v, x) |
Bessel, noninteger order | c-doc • js-doc |
i0(x) |
Modified Bessel, order 0 | c-doc • js-doc |
i0e(x) |
Exponentially scaled i0 | c-doc • js-doc |
i1(x) |
Modified Bessel, order 1 | c-doc • js-doc |
i1e(x) |
Exponentially scaled i1 | c-doc • js-doc |
iv(v, x) |
Modified Bessel, nonint. order | c-doc • js-doc |
k0(x) |
Mod. Bessel, 3rd kind, order 0 | c-doc • js-doc |
k0e(x) |
Exponentially scaled k0 | c-doc • js-doc |
k1(x) |
Mod. Bessel, 3rd kind, order 1 | c-doc • js-doc |
k1e(x) |
Exponentially scaled k1 | c-doc • js-doc |
kn(nn, x) |
Mod. Bessel, 3rd kind, order n | c-doc • js-doc |
Hypergeometric | ||
hyperg(a, b, x) |
Confluent hypergeometric | c-doc • js-doc |
hyp2f1(a, b, c, x) |
Gauss hypergeometric function | c-doc • js-doc |
Elliptic | ||
ellpe(x) |
Complete elliptic integral | c-doc • js-doc |
ellie(phi, m) |
Incomplete elliptic integral | c-doc • js-doc |
ellpk(x) |
Complete elliptic integral | c-doc • js-doc |
ellik(phi, m) |
Incomplete elliptic integral | c-doc • js-doc |
ellpj(u, m) |
Jacobian elliptic function | c-doc • js-doc |
Probability | ||
btdtr(a, b, x) |
Beta distribution | c-doc • js-doc |
smirnov(n, e) |
Exact Smirnov statistic, for one-sided test. | c-doc • js-doc |
kolmogorov(y) |
Kolmogorov's limiting distribution of two-sided test. | c-doc • js-doc |
smirnovi(n, p) |
Functional inverse of Smirnov distribution. | c-doc • js-doc |
kolmogi(p) |
Functional inverse of Kolmogorov statistic for two-sided test. | c-doc • js-doc |
nbdtri(k, n, p) |
Inverse Negative binomial distribution | c-doc • js-doc |
stdtri(k, p) |
Functional inverse of Student's t distribution | c-doc • js-doc |
bdtr(k, n, p) |
Binomial distribution | c-doc • js-doc |
bdtrc(k, n, p) |
Complemented binomial | c-doc • js-doc |
bdtri(k, n, y) |
Inverse binomial | c-doc • js-doc |
chdtr(df, x) |
Chi square distribution | c-doc • js-doc |
chdtrc(df, x) |
Complemented Chi square | c-doc • js-doc |
chdtri(df, y) |
Inverse Chi square | c-doc • js-doc |
fdtr(ia, ib, x) |
F distribution | c-doc • js-doc |
fdtrc(ia, ib, x) |
Complemented F | c-doc • js-doc |
fdtri(ia, ib, y) |
Inverse F distribution | c-doc • js-doc |
gdtr(a, b, x) |
Gamma distribution | c-doc • js-doc |
gdtrc(a, b, x) |
Complemented gamma | c-doc • js-doc |
nbdtr(k, n, p) |
Negative binomial distribution | c-doc • js-doc |
nbdtrc(k, n, p) |
Complemented negative binomial | c-doc • js-doc |
ndtr(a) |
Normal distribution | c-doc • js-doc |
ndtri(y0) |
Inverse normal distribution | c-doc • js-doc |
pdtr(k, m) |
Poisson distribution | c-doc • js-doc |
pdtrc(k, m) |
Complemented Poisson | c-doc • js-doc |
pdtri(k, y) |
Inverse Poisson distribution | c-doc • js-doc |
stdtr(k, t) |
Student's t distribution | c-doc • js-doc |
Miscellaneous | ||
plancki(w, T) |
Integral of Planck's black body radiation formula | c-doc • js-doc |
planckc(w, T) |
Complemented Planck radiation integral | c-doc • js-doc |
planckd(w, T) |
Planck's black body radiation formula | c-doc • js-doc |
planckw(T) |
Wavelength, w, of maximum radiation at given temperature T. | c-doc • js-doc |
spence(x) |
Dilogarithm | c-doc • js-doc |
zetac(x) |
Riemann Zeta function | c-doc • js-doc |
zeta(x, q) |
Two argument zeta function | c-doc • js-doc |
struve(v, x) |
Struve function | c-doc • js-doc |
Polynomials and Power Series | ||
p1evl(x, coef, N) |
Evaluate polynomial when coefficient of x is 1.0. | c-doc • js-doc |
polylog(n, x) |
The polylogarithm of order n | c-doc • js-doc |