Skip to content

foresight_bessel ​

The real Bessel functions of gnuplot 6.0.

gnuplot 6.0 is built with HAVE_JN: besj0, besj1, besy0, besy1, besjn and besyn are the libm j0, j1, y0, y1, jn and yn (standard.c #define rj0(x) j0(x)), reached here through the Fortran 2008 intrinsics bessel_j0/j1/y0/y1/jn, which call the same libm under gfortran and nvfortran; yn is ported from glibc 2.39 (e_jn.c) because its forward recurrence overflows. besi0/besi1 are the Cephes Chebyshev expansions of standard.c (ri0, ri1, chbevl); besin is the Cephes/Boost iv() of specfun.c (Temme's method, uniform asymptotic expansion for orders above 50).

gnuplot marks a result undefined (status 1) when libm sets errno to EDOM or ERANGE during the evaluation (eval.c evaluate_at): exp overflow, exp underflow to zero, log(0), jn/j1 underflow to zero, y0/y1/yn poles and overflow. Infinities and NaNs produced by plain arithmetic are not errors: gnuplot prints them (inf.0, NaN) and these routines return them with status 0. No routine raises an IEEE invalid, divide-by-zero or overflow exception: every operation that could overflow is decided before it is done, and divisions that an optimizer may hoist out of their branch (nvfortran -O2 does) get a harmless stand-in operand. Matching gnuplot needs IEEE subnormals: a build that flushes them to zero (nvfortran 26.9 with foresight's flags) reads subnormal arguments as 0 and loses subnormal intermediates (besin(0, 709) becomes Inf there). Under nvfortran the exp/log/sin/cos intrinsics are not glibc's: besin with |n| > 50 and besjn/besyn for |x| >= 2**302 then differ from gnuplot by tens of ulps (glibc-backed gfortran matches to the last bit).

The order n of besjn, besyn and besin must be a gnuplot integer: when it is a real (even 2.0) gnuplot stops with BESSEL_ERROR (besjn, besyn) or BESIN_ERROR (besin); the caller raises that error (status 2), the routines here take the integer value. All results are real.

Source: src/lib/foresight_bessel.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
BESSEL_ERRORcharacter(len=*)parametergnuplot error for a non-integer order of besjn/besyn.
BESIN_ERRORcharacter(len=*)parametergnuplot error, non-integer besin order.
PIreal(kind=R8P)parameterM_PI.
INVSQRTPIreal(kind=R8P)parameter1/sqrt(pi) of glibc e_jn.c.
EULERreal(kind=R8P)parameterEuler_constant of specfun.c.
MACHEPreal(kind=R8P)parameterDBL_EPSILON.
HUGE_Rreal(kind=R8P)parameterDBL_MAX.
H2real(kind=R8P)parameterDBL_MAX/2: a/2 above it overflows doubled.
H4real(kind=R8P)parameterDBL_MAX/4: a/4 above it overflows times 4.
TWO_1023real(kind=R8P)parameterSums of two numbers below it cannot overflow.
CF1_TINYreal(kind=R8P)parametertiny of CF1_ik, 1/sqrt(DBL_MAX).
EXP_MAXreal(kind=R8P)parameterLargest y with a finite exp(y).
EXP_ZEROreal(kind=R8P)parameterexp(-x) is zero (ERANGE) for x >= EXP_ZERO.
X_LARGEreal(kind=R8P)parameterglibc jn/yn use the sin/cos form from 2**302 up.
Y1_MINreal(kind=R8P)parameterSmallest x with a finite y1(x), 3.5413150332597794e-309 (glibc -tpi/x).
TWO_30integer(kind=I8P)parameterOrders from here up overflow glibc's int loops.
TWO_31integer(kind=I8P)parameterINT_MIN magnitude.
TWO_32integer(kind=I8P)parameterint wrap modulus.
MAXITERinteger(kind=I4P)parameterMAXITER of specfun.c.
CHEB_I0_Areal(kind=R8P)parameterexp(-x) I0(x) on [0,8], Chebyshev (standard.c cheb_i0_A).
CHEB_I1_Areal(kind=R8P)parameterexp(-x) I1(x)/x on [0,8], Chebyshev (standard.c cheb_i1_A).
CHEB_I0_Breal(kind=R8P)parameterexp(-x) sqrt(x) I0(x) on [8,inf] (cheb_i0_B).
CHEB_I1_Breal(kind=R8P)parameterexp(-x) sqrt(x) I1(x) on [8,inf] (cheb_i1_B).
UFACTORSreal(kind=R8P)parameteru_n(t) of AMS 9.3.9 (asymptotic_ufactors).

Subroutines ​

gp_besj0 ​

gnuplot besj0(x) (standard.c f_besj0): libm j0. Defined everywhere.

Attributes: pure

fortran
subroutine gp_besj0(x, r, status)

Arguments

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

Call graph

gp_besj1 ​

gnuplot besj1(x) (standard.c f_besj1): libm j1. Undefined when j1 underflows to zero (ERANGE), x = 4.9e-324.

Attributes: pure

fortran
subroutine gp_besj1(x, r, status)

Arguments

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

Call graph

gp_besy0 ​

gnuplot besy0(x) (standard.c f_besy0): libm y0 for x > 0, undefined for x <= 0.

Attributes: pure

fortran
subroutine gp_besy0(x, r, status)

Arguments

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

Call graph

gp_besy1 ​

gnuplot besy1(x) (standard.c f_besy1): libm y1 for x > 0; undefined for x <= 0 and where y1 overflows (ERANGE).

Attributes: pure

fortran
subroutine gp_besy1(x, r, status)

Arguments

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

Call graph

gp_besjn ​

gnuplot besjn(n, x) (standard.c f_besjn): libm jn((int)n, x), as glibc 2.39 __ieee754_jn. Undefined when jn underflows to zero (ERANGE). The order is truncated to a C int as gnuplot does; for |int n| >= 230 glibc's int arithmetic overflows (undefined behaviour, runs of seconds, NaN): there the result is computed only for x = 0 and |x| >= 2302 (well defined) and is undefined otherwise.

Attributes: pure

fortran
subroutine gp_besjn(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_besyn ​

gnuplot besyn(n, x) (standard.c f_besyn): libm yn((int)n, x), ported from glibc 2.39 __ieee754_yn so that the overflow of its forward recurrence is detected before it happens. Undefined for x <= 0 and where yn overflows (ERANGE). For 230 <= |int n| < 231 glibc's loop counter overflows: undefined unless x >= 2**302.

Attributes: pure

fortran
subroutine gp_besyn(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_besi0 ​

gnuplot besi0(x) (standard.c f_besi0, ri0): Chebyshev expansions of exp(-x) I0(x). Undefined where exp(|x|) overflows (ERANGE), |x| > 709.78271289338397.

Attributes: pure

fortran
subroutine gp_besi0(x, r, status)

Arguments

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

Call graph

gp_besi1 ​

gnuplot besi1(x) (standard.c f_besi1, ri1): Chebyshev expansions of exp(-x) I1(x). Undefined where exp(|x|) overflows (ERANGE), |x| > 709.78271289338397.

Attributes: pure

fortran
subroutine gp_besi1(x, r, status)

Arguments

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

Call graph

gp_besin ​

gnuplot besin(n, x) (specfun.c f_besin, iv): modified Bessel function I_n(x) of integer order. Undefined where libm sets ERANGE: exp(-x) underflowing to zero (x >= 745.13321910194122), exp overflow in the uniform expansion (|n| > 50), log(0) for x = 4.9e-324. Returns +-Inf (gnuplot prints inf.0) where the Temme quotient overflows, NaN (gnuplot prints NaN) where its continued fraction CF1 overflows (x below ~1e-308).

Attributes: pure

fortran
subroutine gp_besin(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

undefined ​

Set gnuplot's undefined value.

Attributes: pure

fortran
subroutine undefined(r, status)

Arguments

NameTypeIntentAttributesDescription
rreal(kind=R8P)outResult, 0.
statusinteger(kind=I4P)out1.

Call graph

mul_safe ​

p = a*b exactly as IEEE rounds it, or ovf when that product overflows. The one multiplication is always done on operands that cannot overflow (scaled or zeroed beforehand), so no branch can raise even if speculated.

Attributes: pure

fortran
subroutine mul_safe(a, b, p, ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inFactor.
breal(kind=R8P)inFactor.
preal(kind=R8P)outProduct (0 on overflow).
ovflogicaloutThe product overflows.

Call graph

div_safe ​

q = a/b exactly as IEEE rounds it, or ovf when that quotient overflows or b is zero. The one division is always done on operands that cannot raise (scaled or replaced beforehand), so no branch can raise even if speculated.

Attributes: pure

fortran
subroutine div_safe(a, b, q, ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inDividend.
breal(kind=R8P)inDivisor.
qreal(kind=R8P)outQuotient (0 on overflow).
ovflogicaloutThe quotient overflows (or b = 0).

Call graph

add_safe ​

s = a+b exactly as IEEE rounds it, or ovf when that sum overflows. Operands from 2**1023 up are halved first.

Attributes: pure

fortran
subroutine add_safe(a, b, s, ovf)

Arguments

NameTypeIntentAttributesDescription
areal(kind=R8P)inAddend.
breal(kind=R8P)inAddend.
sreal(kind=R8P)outSum (0 on overflow).
ovflogicaloutThe sum overflows.

Call graph

iv ​

Modified Bessel function I_v(x) (specfun.c iv), for the integral v that f_besin passes.

Attributes: pure

fortran
subroutine iv(v, x, r, status)

Arguments

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

Call graph

ikv_asymptotic_uniform ​

I_v(x) by the uniform asymptotic expansion for large v, AMS 9.7.7 (specfun.c ikv_asymptotic_uniform), v > 50. Undefined where exp(+-v eta) overflows or log meets 0 (libm ERANGE); the K part is not needed by besin.

Attributes: pure

fortran
subroutine ikv_asymptotic_uniform(v, x, r, status)

Arguments

NameTypeIntentAttributesDescription
vreal(kind=R8P)inOrder (> 50).
xreal(kind=R8P)inArgument (> 0).
rreal(kind=R8P)outResult.
statusinteger(kind=I4P)out0 value, 1 undefined.

Call graph

ikv_temme ​

I_v(x) by Temme's method (specfun.c ikv_temme, from Boost bessel_ik), integer 0 <= v <= 50 (so u = 0), x > 0, I only (no reflection: iv() has already made integer orders non-negative). K_u and K_u+1 from the Temme series (x <= 2) or CF2_ik, forward recurrence to K_v, CF1_ik for I_v+1/I_v and the Wronskian. The infinities gnuplot's arithmetic produces on the way are tracked as flags, not computed.

Attributes: pure

fortran
subroutine ikv_temme(v, x, r, status)

Arguments

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

Call graph

temme_ik_series ​

K_0(x) and K_1(x) by Temme's series, x <= 2 (specfun.c temme_ik_series at v = 0, the only order u = v - n that integer orders give). At v = 0 gnuplot's set-up reduces exactly (tgamma(1) = exp(0) = cosh(0) = 1, the ternaries take their limits) to gp = gm = 0, c = d = 1, gamma1 = -Euler, gamma2 = 1, p = q = 1/2 and f = -Euler - log(x/2); the v-dependent quotients are left out because optimizing compilers evaluate them speculatively (0/0) even on the branch gnuplot does not take.

Attributes: pure

fortran
subroutine temme_ik_series(x, k, k1, k1_inf)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument, 0 0.
kreal(kind=R8P)outK_0.
k1real(kind=R8P)outK_1 (0 when k1_inf).
k1_inflogicaloutK_1 = 2 sum1/x overflows.

Call graph

cf1_ik ​

I_v+1(x)/I_v(x) by the continued fraction A&S 9.1.73, modified Lentz (specfun.c CF1_ik). When 2(v+k)/x overflows gnuplot computes Inf*0 and the fraction is NaN: fv_nan.

Attributes: pure

fortran
subroutine cf1_ik(v, x, fv, fv_nan)

Arguments

NameTypeIntentAttributesDescription
vreal(kind=R8P)inOrder.
xreal(kind=R8P)inArgument (> 0).
fvreal(kind=R8P)outI_v+1/I_v.
fv_nanlogicaloutThe fraction is NaN.

Call graph

cf2_ik ​

K_v(x) and K_v+1(x) by Steed's continued fraction, Thompson and Barnett (specfun.c CF2_ik), 2 < x < 745.13.

Attributes: pure

fortran
subroutine cf2_ik(v, x, kv, kv1)

Arguments

NameTypeIntentAttributesDescription
vreal(kind=R8P)inOrder, |v| <= 1/2.
xreal(kind=R8P)inArgument.
kvreal(kind=R8P)outK_v.
kv1real(kind=R8P)outK_v+1.

Call graph

Functions ​

c_int ​

The value of the C int that an int64 order converts to (gcc wraps modulo 2**32), as an I8P.

Attributes: pure

Returns: integer(kind=I8P)

fortran
function c_int(n) result(m)

Arguments

NameTypeIntentAttributesDescription
ninteger(kind=I8P)ingnuplot integer.

Call graph

chbevl ​

Chebyshev series of the coefficients array at x/2 (standard.c chbevl).

Attributes: pure

Returns: real(kind=R8P)

fortran
function chbevl(x, array) result(r)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.
arrayreal(kind=R8P)inCoefficients, highest order first.

Call graph

c_floor ​

C floor() of a real, without conversion to an integer kind.

Attributes: pure

Returns: real(kind=R8P)

fortran
function c_floor(x) result(f)

Arguments

NameTypeIntentAttributesDescription
xreal(kind=R8P)inArgument.

Call graph

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