Skip to content

foresight_specfun ​

gnuplot 6.0.0 real special functions, ported from its own C sources so values match gnuplot's to the last digits.

Every entry point is a pure subroutine gp_<name>(args..., r, status): status 0 = value in r (it can be NaN or +Inf when gnuplot prints NaN or inf); status 1 = gnuplot's undefined value (it prints "undefined value", plots a gap); status 2 = gnuplot stops with an error (no entry point here returns it: see EXPINT_ORDER_MSG). gnuplot flags "undefined" also when a libm call sets errno (EDOM, ERANGE): those cases are reproduced by guards. No IEEE invalid, divide-by-zero or overflow exception is raised for any finite argument. All results are real (gnuplot complex values with zero imaginary part).

Source: src/lib/foresight_specfun.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
EXPINT_ORDER_MSGcharacter(len=*)parametergnuplot int_error of expint(n, x) when n is not integer-typed.
PIreal(kind=R8P)parameterM_PI.
E_ONEreal(kind=R8P)parameterexp(1.0), constant-folded by gcc.
E_MONEreal(kind=R8P)parameterexp(-1), constant-folded by gcc.
FLT_EPSreal(kind=R8P)parameterFLT_EPSILON.
DBL_EPSreal(kind=R8P)parameterDBL_EPSILON (cephes MACHEP).
FLT_MAXVreal(kind=R8P)parameterFLT_MAX (specfun.c OFLOW).
TWO_512real(kind=R8P)parameterSquares of values from here on overflow.
TWO_1021real(kind=R8P)parameterOverflow threshold of a product scaled by 1/8.
TWO_1023real(kind=R8P)parameterOverflow threshold of a sum scaled by 1/2.
EXP_ZEROreal(kind=R8P)parameterglibc exp(x) == 0 (errno ERANGE) for x <= this.
POW113_ZEROreal(kind=R8P)parameterglibc pow(x, 11/3) == 0 for 0 < x <= this.
QNAN_BITSinteger(kind=I8P)parameterQuiet NaN bit pattern.
PINF_BITSinteger(kind=I8P)parameter+Inf bit pattern.
EXP_MAX_ARGreal(kind=R8P)parameterLargest x with finite exp(x).
TWO_60real(kind=R8P)parameterScale to compare subnormals with normal constants.
TWO_M964real(kind=R8P)parameter2**-1024 * 260: 1/z overflows for z <= 2-1024.
AIRY_C1real(kind=R8P)parameterAi(0).
AIRY_C2real(kind=R8P)parameter-Ai'(0).
AIRY_SQPIIreal(kind=R8P)parameter1/sqrt(pi).
MAXAIRYreal(kind=R8P)parameterAi(x) = 0 beyond.
ANreal(kind=R8P)parameterAi numerator, x>2.09.
ADreal(kind=R8P)parameterAi denominator, x>2.09.
AFNreal(kind=R8P)parameterAi modulus numerator, x<-2.09.
AFDreal(kind=R8P)parameterAi modulus denominator (leading 1 implied).
AGNreal(kind=R8P)parameterAi phase numerator, x<-2.09.
AGDreal(kind=R8P)parameterAi phase denom.
HUM_Creal(kind=R8P)parameterCPF12 c.
HUM_Sreal(kind=R8P)parameterCPF12 s.
HUM_Treal(kind=R8P)parameterCPF12 t.
HUM_RRTPIreal(kind=R8P)parameter1/sqrt(pi) as in humlik.
LANCZOSreal(kind=R8P)parametercoef.
LANCZOS_SQRT2PIreal(kind=R8P)parametersqrt(2 pi) as in lnGamma.
LANCZOS_Greal(kind=R8P)parameterLanczos g.
SYN_F1real(kind=R8P)parameterf1.
SYN_F2real(kind=R8P)parameterf2.
SYN_F3real(kind=R8P)parameterf3.
SYN_F4real(kind=R8P)parameterf4.

Interfaces ​

c_log1p ​

Subroutines ​

gp_lambertw ​

lambertw(x), principal branch: specfun.c lambertw (Halley iteration) and f_lambertw. Undefined (status 1) for x < -1/e, on non-convergence and for results <= -1 (as f_lambertw).

Attributes: pure

fortran
subroutine gp_lambertw(x, r, status)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_airy ​

airy(x) = Ai(x): specfun.c airy (cephes 2.8, UNK tables) and f_airy, which pushes only Ai. Ai = 0 for x > 25.77 (MAXAIRY); undefined (status 1) when -2x*sqrt(-x) overflows (sin(inf) sets EDOM).

Attributes: pure

fortran
subroutine gp_airy(x, r, status)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_expint ​

expint(n, x) = E_n(x): specfun.c expint (A&S 5.1.22 continued fraction for x > 3, series 5.1.12 and recurrence 5.1.14 otherwise) and f_expint. Undefined (status 1) for n < 0, x < 0, x = 0 with n < 2, and when exp(-x) underflows to 0 (x > 745.13, glibc errno ERANGE). gnuplot stops with EXPINT_ORDER_MSG when n is not integer-typed: the caller checks it. expint(0, x) overflows to +Inf (status 0) for x <= 2**-1024. For x <= 3 the recurrence runs n-1 steps as in gnuplot; for n >= 2**53 gnuplot never terminates, here it returns undefined.

Attributes: pure

fortran
subroutine gp_expint(n, x, r, status)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)inOrder (gnuplot integer).
xreal(kind=R8P)inArgument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_EllipticK ​

EllipticK(k), complete elliptic integral of the first kind: standard.c f_ellip_first, Carlson R_F(0, 1-k^2, 1). Undefined (status 1) for |k| >= 1.

Attributes: pure

fortran
subroutine gp_EllipticK(k, r, status)

Arguments

NameTypeIntentAttributesDescription
kreal(kind=R8P)inModulus.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_EllipticE ​

EllipticE(k), complete elliptic integral of the second kind: standard.c f_ellip_second, R_F(0, q, 1) - k^2 R_D(0, q, 1)/3 with q = 1-k^2. E(+-1) = 1; undefined (status 1) for |k| > 1.

Attributes: pure

fortran
subroutine gp_EllipticE(k, r, status)

Arguments

NameTypeIntentAttributesDescription
kreal(kind=R8P)inModulus.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_EllipticPi ​

EllipticPi(n, k), complete elliptic integral of the third kind: standard.c f_ellip_third, R_F(0, q, 1) + n R_J(0, q, 1, 1-n)/3 with q = 1-k^2. Undefined (status 1) for |k| >= 1 or n >= 1. For n below about -4.5e102 gnuplot's R_J overflows and the result is NaN (status 0), reproduced here.

Attributes: pure

fortran
subroutine gp_EllipticPi(n, k, r, status)

Arguments

NameTypeIntentAttributesDescription
nreal(kind=R8P)inCharacteristic.
kreal(kind=R8P)inModulus.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_voigt ​

voigt(x, y), Voigt profile K(x, y): specfun.c f_voigt fallback (no libcerf) = humlik, Humlicek W4/CPF12. Undefined (status 1) for y below about -10.81 (sqrt of a negative xlim, EDOM) and, for y <= 1e-6, when exp(-x^2) underflows to 0 in CPF12 region II (|x| > 27.29, ERANGE). NaN (status 0) when a CPF12 denominator is exactly zero (y = -1.5 and x = +-t_j), as in gnuplot.

Attributes: pure

fortran
subroutine gp_voigt(x, y, r, status)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inReal part of the complex argument.
yreal(kind=R8P)inImaginary part of the complex argument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

gp_zeta ​

zeta(s), Riemann zeta for real s: complexfun.c f_zeta and Riemann_zeta (Borwein algorithm 3, n = 18), the reflection formula with the Lanczos lnGamma for s < 0, glibc cpow/clog/csin/cexp reduced to real arithmetic. zeta(s) = 1 for s > 55; NaN (status 0) for s < -170; 0 at negative even integers; +Inf (status 0) where 1 - 2**(1-s) rounds to 0 (s = 1 and its neighbours: gnuplot gives {inf, NaN}, a complex with NaN imaginary).

Attributes: pure

fortran
subroutine gp_zeta(s, r, status)

Arguments

NameTypeIntentAttributesDescription
sreal(kind=R8P)inArgument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value.

Call graph

gp_SynchrotronF ​

SynchrotronF(x) = x * int_x^inf K_{5/3}(y) dy: specfun.c f_SynchrotronF (MacLeod 2000 Chebyshev fits). NaN (status 0) for x < 0, 0 for x > 745; undefined (status 1) when x**(11/3) underflows to 0 (0 < x < ~7e-89, glibc pow sets errno ERANGE).

Attributes: pure

fortran
subroutine gp_SynchrotronF(x, r, status)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

carlson_rc ​

standard.c carlson_elliptic_rc for y > 0 (the only case R_J with p > 0 calls), Carlson R_C(x, y). nan is true where gnuplot's iteration overflows to Inf and ends in NaN.

Attributes: pure

fortran
subroutine carlson_rc(x, y, v, nan)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inFirst argument.
yreal(kind=R8P)inSecond argument, > 0.
vreal(kind=R8P)outValue.
nanlogicaloutOverflow (NaN result in gnuplot).

Call graph

carlson_rj ​

standard.c carlson_elliptic_rj for p > 0 (EllipticPi always has p = 1-n > 0), Carlson R_J(x, y, z, p). nan is true where gnuplot's alpha/beta (or R_C) overflow to Inf and the result is NaN.

Attributes: pure

fortran
subroutine carlson_rj(x, y, z, p, v, nan)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inFirst argument.
yreal(kind=R8P)inSecond argument.
zreal(kind=R8P)inThird argument.
preal(kind=R8P)inFourth argument, > 0.
vreal(kind=R8P)outValue.
nanlogicaloutOverflow (NaN result in gnuplot).

Call graph

Functions ​

add_overflows ​

True when a + b (a, b >= 0, finite) rounds to +Inf: the halved sum reaches 2**1023 (halving is exact).

Attributes: pure

Returns: logical

fortran
function add_overflows(a, b) result(ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inFirst addend.
breal(kind=R8P)inSecond addend.

Call graph

mul_overflows ​

True when a * b (a, b >= 0, finite) rounds to +Inf: exponent bound, then the product scaled by 1/8.

Attributes: pure

Returns: logical

fortran
function mul_overflows(a, b) result(ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inFirst factor.
breal(kind=R8P)inSecond factor.

Call graph

div_overflows ​

True when a / b (a, b >= 0, finite, b /= 0) rounds to +Inf: exponent bound, then the quotient scaled by 1/8.

Attributes: pure

Returns: logical

fortran
function div_overflows(a, b) result(ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inDividend.
breal(kind=R8P)inDivisor.

Call graph

region0 ​

humlik region 0, y/sqrt(pi)/(x^2 + y^2), returning gnuplot's signed zero where x^2 + y^2 overflows.

Attributes: pure

Returns: real(kind=R8P)

fortran
function region0(abx, y, yrrtpi) result(v)

Arguments

NameTypeIntentAttributesDescription
abxreal(kind=R8P)in|x|.
yreal(kind=R8P)iny.
yrrtpireal(kind=R8P)iny/sqrt(pi).

Call graph

polevl ​

cephes polevl: coef(1)*x**n + ... + coef(n+1), Horner.

Attributes: pure

Returns: real(kind=R8P)

fortran
function polevl(x, coef, n) result(ans)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
coefreal(kind=R8P)inCoefficients, highest degree first.
ninteger(kind=I4P)inDegree.

Call graph

p1evl ​

cephes p1evl: x*n + coef(1)x(n-1) + ... + coef(n), Horner with implied leading 1.

Attributes: pure

Returns: real(kind=R8P)

fortran
function p1evl(x, coef, n) result(ans)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
coefreal(kind=R8P)inCoefficients after the leading 1.
ninteger(kind=I4P)inDegree.

Call graph

expand_cheby ​

specfun.c expand_cheby: Clenshaw sum of a Chebyshev series, halved leading term.

Attributes: pure

Returns: real(kind=R8P)

fortran
function expand_cheby(t, coef, n) result(v)

Arguments

NameTypeIntentAttributesDescription
treal(kind=R8P)inArgument in [-1, 1].
coefreal(kind=R8P)inCoefficients.
ninteger(kind=I4P)inNumber of coefficients.

Call graph

carlson_rf ​

standard.c carlson_elliptic_rf, Carlson R_F(x, y, z) (Numerical Recipes rf, ERRTOL 0.0025).

Attributes: pure

Returns: real(kind=R8P)

fortran
function carlson_rf(x, y, z) result(v)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inFirst argument.
yreal(kind=R8P)inSecond argument.
zreal(kind=R8P)inThird argument.

Call graph

carlson_rd ​

standard.c carlson_elliptic_rd, Carlson R_D(x, y, z) (Numerical Recipes rd, ERRTOL 0.0015).

Attributes: pure

Returns: real(kind=R8P)

fortran
function carlson_rd(x, y, z) result(v)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inFirst argument.
yreal(kind=R8P)inSecond argument.
zreal(kind=R8P)inThird argument.

Call graph

clog_re ​

Real part of glibc clog(v + 0i) for finite v > 0: log1p((v-1)(v+1))/2 for 0.5 <= v < 2, else log(v).

Attributes: pure

Returns: real(kind=R8P)

fortran
function clog_re(v) result(l)

Arguments

NameTypeIntentAttributesDescription
vreal(kind=R8P)inArgument, > 0.

Call graph

lngamma_lanczos ​

complexfun.c lnGamma (14-term Lanczos, Numerical Recipes form) for real z >= 1.

Attributes: pure

Returns: real(kind=R8P)

fortran
function lngamma_lanczos(z) result(f)

Arguments

NameTypeIntentAttributesDescription
zreal(kind=R8P)inArgument, >= 1.

Call graph

riemann_zeta ​

complexfun.c Riemann_zeta for real s >= 0 (cpow(j, s) = exp(s*log(j)) as glibc evaluates it for real s). +Inf where 1 - 2**(1-s) rounds to 0 (gnuplot: libgcc complex division by 0 gives {inf, NaN}).

Attributes: pure

Returns: real(kind=R8P)

fortran
function riemann_zeta(s) result(v)

Arguments

NameTypeIntentAttributesDescription
sreal(kind=R8P)inArgument.

Call graph

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.