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
- gp_besj0
- gp_besj1
- gp_besy0
- gp_besy1
- gp_besjn
- gp_besyn
- gp_besi0
- gp_besi1
- gp_besin
- undefined
- mul_safe
- div_safe
- add_safe
- iv
- ikv_asymptotic_uniform
- ikv_temme
- temme_ik_series
- cf1_ik
- cf2_ik
- c_int
- chbevl
- c_floor
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
BESSEL_ERROR | character(len=*) | parameter | gnuplot error for a non-integer order of besjn/besyn. |
BESIN_ERROR | character(len=*) | parameter | gnuplot error, non-integer besin order. |
PI | real(kind=R8P) | parameter | M_PI. |
INVSQRTPI | real(kind=R8P) | parameter | 1/sqrt(pi) of glibc e_jn.c. |
EULER | real(kind=R8P) | parameter | Euler_constant of specfun.c. |
MACHEP | real(kind=R8P) | parameter | DBL_EPSILON. |
HUGE_R | real(kind=R8P) | parameter | DBL_MAX. |
H2 | real(kind=R8P) | parameter | DBL_MAX/2: a/2 above it overflows doubled. |
H4 | real(kind=R8P) | parameter | DBL_MAX/4: a/4 above it overflows times 4. |
TWO_1023 | real(kind=R8P) | parameter | Sums of two numbers below it cannot overflow. |
CF1_TINY | real(kind=R8P) | parameter | tiny of CF1_ik, 1/sqrt(DBL_MAX). |
EXP_MAX | real(kind=R8P) | parameter | Largest y with a finite exp(y). |
EXP_ZERO | real(kind=R8P) | parameter | exp(-x) is zero (ERANGE) for x >= EXP_ZERO. |
X_LARGE | real(kind=R8P) | parameter | glibc jn/yn use the sin/cos form from 2**302 up. |
Y1_MIN | real(kind=R8P) | parameter | Smallest x with a finite y1(x), 3.5413150332597794e-309 (glibc -tpi/x). |
TWO_30 | integer(kind=I8P) | parameter | Orders from here up overflow glibc's int loops. |
TWO_31 | integer(kind=I8P) | parameter | INT_MIN magnitude. |
TWO_32 | integer(kind=I8P) | parameter | int wrap modulus. |
MAXITER | integer(kind=I4P) | parameter | MAXITER of specfun.c. |
CHEB_I0_A | real(kind=R8P) | parameter | exp(-x) I0(x) on [0,8], Chebyshev (standard.c cheb_i0_A). |
CHEB_I1_A | real(kind=R8P) | parameter | exp(-x) I1(x)/x on [0,8], Chebyshev (standard.c cheb_i1_A). |
CHEB_I0_B | real(kind=R8P) | parameter | exp(-x) sqrt(x) I0(x) on [8,inf] (cheb_i0_B). |
CHEB_I1_B | real(kind=R8P) | parameter | exp(-x) sqrt(x) I1(x) on [8,inf] (cheb_i1_B). |
UFACTORS | real(kind=R8P) | parameter | u_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
subroutine gp_besj0(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_besj1
gnuplot besj1(x) (standard.c f_besj1): libm j1. Undefined when j1 underflows to zero (ERANGE), x = 4.9e-324.
Attributes: pure
subroutine gp_besj1(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_besy0
gnuplot besy0(x) (standard.c f_besy0): libm y0 for x > 0, undefined for x <= 0.
Attributes: pure
subroutine gp_besy0(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_besy1
gnuplot besy1(x) (standard.c f_besy1): libm y1 for x > 0; undefined for x <= 0 and where y1 overflows (ERANGE).
Attributes: pure
subroutine gp_besy1(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_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
subroutine gp_besjn(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_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
subroutine gp_besyn(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_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
subroutine gp_besi0(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_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
subroutine gp_besi1(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_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
subroutine gp_besin(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
undefined
Set gnuplot's undefined value.
Attributes: pure
subroutine undefined(r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
r | real(kind=R8P) | out | Result, 0. | |
status | integer(kind=I4P) | out | 1. |
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
subroutine mul_safe(a, b, p, ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | Factor. | |
b | real(kind=R8P) | in | Factor. | |
p | real(kind=R8P) | out | Product (0 on overflow). | |
ovf | logical | out | The 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
subroutine div_safe(a, b, q, ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | Dividend. | |
b | real(kind=R8P) | in | Divisor. | |
q | real(kind=R8P) | out | Quotient (0 on overflow). | |
ovf | logical | out | The 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
subroutine add_safe(a, b, s, ovf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
a | real(kind=R8P) | in | Addend. | |
b | real(kind=R8P) | in | Addend. | |
s | real(kind=R8P) | out | Sum (0 on overflow). | |
ovf | logical | out | The sum overflows. |
Call graph
iv
Modified Bessel function I_v(x) (specfun.c iv), for the integral v that f_besin passes.
Attributes: pure
subroutine iv(v, x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Order. | |
x | real(kind=R8P) | in | Argument. | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine ikv_asymptotic_uniform(v, x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Order (> 50). | |
x | real(kind=R8P) | in | Argument (> 0). | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine ikv_temme(v, x, r, status)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Order. | |
x | real(kind=R8P) | in | Argument (> 0). | |
r | real(kind=R8P) | out | Result. | |
status | integer(kind=I4P) | out | 0 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
subroutine temme_ik_series(x, k, k1, k1_inf)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument, 0 0. | |
k | real(kind=R8P) | out | K_0. | |
k1 | real(kind=R8P) | out | K_1 (0 when k1_inf). | |
k1_inf | logical | out | K_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
subroutine cf1_ik(v, x, fv, fv_nan)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Order. | |
x | real(kind=R8P) | in | Argument (> 0). | |
fv | real(kind=R8P) | out | I_v+1/I_v. | |
fv_nan | logical | out | The 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
subroutine cf2_ik(v, x, kv, kv1)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
v | real(kind=R8P) | in | Order, |v| <= 1/2. | |
x | real(kind=R8P) | in | Argument. | |
kv | real(kind=R8P) | out | K_v. | |
kv1 | real(kind=R8P) | out | K_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)
function c_int(n) result(m)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
n | integer(kind=I8P) | in | gnuplot integer. |
Call graph
chbevl
Chebyshev series of the coefficients array at x/2 (standard.c chbevl).
Attributes: pure
Returns: real(kind=R8P)
function chbevl(x, array) result(r)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. | |
array | real(kind=R8P) | in | Coefficients, highest order first. |
Call graph
c_floor
C floor() of a real, without conversion to an integer kind.
Attributes: pure
Returns: real(kind=R8P)
function c_floor(x) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
x | real(kind=R8P) | in | Argument. |
Call graph