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
- c_log1p
- gp_lambertw
- gp_airy
- gp_expint
- gp_EllipticK
- gp_EllipticE
- gp_EllipticPi
- gp_voigt
- gp_zeta
- gp_SynchrotronF
- carlson_rc
- carlson_rj
- add_overflows
- mul_overflows
- div_overflows
- region0
- polevl
- p1evl
- expand_cheby
- carlson_rf
- carlson_rd
- clog_re
- lngamma_lanczos
- riemann_zeta
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
EXPINT_ORDER_MSG | character(len=*) | parameter | gnuplot int_error of expint(n, x) when n is not integer-typed. |
PI | real(kind=R8P) | parameter | M_PI. |
E_ONE | real(kind=R8P) | parameter | exp(1.0), constant-folded by gcc. |
E_MONE | real(kind=R8P) | parameter | exp(-1), constant-folded by gcc. |
FLT_EPS | real(kind=R8P) | parameter | FLT_EPSILON. |
DBL_EPS | real(kind=R8P) | parameter | DBL_EPSILON (cephes MACHEP). |
FLT_MAXV | real(kind=R8P) | parameter | FLT_MAX (specfun.c OFLOW). |
TWO_512 | real(kind=R8P) | parameter | Squares of values from here on overflow. |
TWO_1021 | real(kind=R8P) | parameter | Overflow threshold of a product scaled by 1/8. |
TWO_1023 | real(kind=R8P) | parameter | Overflow threshold of a sum scaled by 1/2. |
EXP_ZERO | real(kind=R8P) | parameter | glibc exp(x) == 0 (errno ERANGE) for x <= this. |
POW113_ZERO | real(kind=R8P) | parameter | glibc pow(x, 11/3) == 0 for 0 < x <= this. |
QNAN_BITS | integer(kind=I8P) | parameter | Quiet NaN bit pattern. |
PINF_BITS | integer(kind=I8P) | parameter | +Inf bit pattern. |
EXP_MAX_ARG | real(kind=R8P) | parameter | Largest x with finite exp(x). |
TWO_60 | real(kind=R8P) | parameter | Scale to compare subnormals with normal constants. |
TWO_M964 | real(kind=R8P) | parameter | 2**-1024 * 260: 1/z overflows for z <= 2-1024. |
AIRY_C1 | real(kind=R8P) | parameter | Ai(0). |
AIRY_C2 | real(kind=R8P) | parameter | -Ai'(0). |
AIRY_SQPII | real(kind=R8P) | parameter | 1/sqrt(pi). |
MAXAIRY | real(kind=R8P) | parameter | Ai(x) = 0 beyond. |
AN | real(kind=R8P) | parameter | Ai numerator, x>2.09. |
AD | real(kind=R8P) | parameter | Ai denominator, x>2.09. |
AFN | real(kind=R8P) | parameter | Ai modulus numerator, x<-2.09. |
AFD | real(kind=R8P) | parameter | Ai modulus denominator (leading 1 implied). |
AGN | real(kind=R8P) | parameter | Ai phase numerator, x<-2.09. |
AGD | real(kind=R8P) | parameter | Ai phase denom. |
HUM_C | real(kind=R8P) | parameter | CPF12 c. |
HUM_S | real(kind=R8P) | parameter | CPF12 s. |
HUM_T | real(kind=R8P) | parameter | CPF12 t. |
HUM_RRTPI | real(kind=R8P) | parameter | 1/sqrt(pi) as in humlik. |
LANCZOS | real(kind=R8P) | parameter | coef. |
LANCZOS_SQRT2PI | real(kind=R8P) | parameter | sqrt(2 pi) as in lnGamma. |
LANCZOS_G | real(kind=R8P) | parameter | Lanczos g. |
SYN_F1 | real(kind=R8P) | parameter | f1. |
SYN_F2 | real(kind=R8P) | parameter | f2. |
SYN_F3 | real(kind=R8P) | parameter | f3. |
SYN_F4 | real(kind=R8P) | parameter | f4. |
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
subroutine gp_lambertw(x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_airy(x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_expint(n, x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
n | integer(kind=I8P) | in | Order (gnuplot integer). | |
x | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_EllipticK(k, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
k | real(kind=R8P) | in | Modulus. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_EllipticE(k, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
k | real(kind=R8P) | in | Modulus. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_EllipticPi(n, k, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
n | real(kind=R8P) | in | Characteristic. | |
k | real(kind=R8P) | in | Modulus. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_voigt(x, y, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Real part of the complex argument. | |
y | real(kind=R8P) | in | Imaginary part of the complex argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_zeta(s, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
s | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine gp_SynchrotronF(x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine carlson_rc(x, y, v, nan)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | First argument. | |
y | real(kind=R8P) | in | Second argument, > 0. | |
v | real(kind=R8P) | out | Value. | |
nan | logical | out | Overflow (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
subroutine carlson_rj(x, y, z, p, v, nan)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | First argument. | |
y | real(kind=R8P) | in | Second argument. | |
z | real(kind=R8P) | in | Third argument. | |
p | real(kind=R8P) | in | Fourth argument, > 0. | |
v | real(kind=R8P) | out | Value. | |
nan | logical | out | Overflow (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
function add_overflows(a, b) result(ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | First addend. | |
b | real(kind=R8P) | in | Second 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
function mul_overflows(a, b) result(ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | First factor. | |
b | real(kind=R8P) | in | Second 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
function div_overflows(a, b) result(ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | Dividend. | |
b | real(kind=R8P) | in | Divisor. |
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)
function region0(abx, y, yrrtpi) result(v)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
abx | real(kind=R8P) | in | |x|. | |
y | real(kind=R8P) | in | y. | |
yrrtpi | real(kind=R8P) | in | y/sqrt(pi). |
Call graph
polevl
cephes polevl: coef(1)*x**n + ... + coef(n+1), Horner.
Attributes: pure
Returns: real(kind=R8P)
function polevl(x, coef, n) result(ans)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
coef | real(kind=R8P) | in | Coefficients, highest degree first. | |
n | integer(kind=I4P) | in | Degree. |
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)
function p1evl(x, coef, n) result(ans)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
coef | real(kind=R8P) | in | Coefficients after the leading 1. | |
n | integer(kind=I4P) | in | Degree. |
Call graph
expand_cheby
specfun.c expand_cheby: Clenshaw sum of a Chebyshev series, halved leading term.
Attributes: pure
Returns: real(kind=R8P)
function expand_cheby(t, coef, n) result(v)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
t | real(kind=R8P) | in | Argument in [-1, 1]. | |
coef | real(kind=R8P) | in | Coefficients. | |
n | integer(kind=I4P) | in | Number 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)
function carlson_rf(x, y, z) result(v)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | First argument. | |
y | real(kind=R8P) | in | Second argument. | |
z | real(kind=R8P) | in | Third 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)
function carlson_rd(x, y, z) result(v)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | First argument. | |
y | real(kind=R8P) | in | Second argument. | |
z | real(kind=R8P) | in | Third 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)
function clog_re(v) result(l)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Argument, > 0. |
Call graph
lngamma_lanczos
complexfun.c lnGamma (14-term Lanczos, Numerical Recipes form) for real z >= 1.
Attributes: pure
Returns: real(kind=R8P)
function lngamma_lanczos(z) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
z | real(kind=R8P) | in | Argument, >= 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)
function riemann_zeta(s) result(v)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
s | real(kind=R8P) | in | Argument. |
Call graph