fortran-bessels
Fast, accurate Bessel functions in pure modern Fortran
Loading...
Searching...
No Matches
fortran-bessels

fortran-bessels is a Modern Fortran (2008+) port of Bessels.jl, built for one thing: evaluating Bessel functions as fast and as accurately as possible in pure Fortran. The fixed-order kernels beat the gfortran intrinsics by roughly 2× and the netlib specfun reference by orders of magnitude, while matching them to a few units in the last place (ULP).

Every function is an elemental real(BK) function (BK = real64), so it accepts a scalar or a whole array interchangeably — no wrapper loops, no temporaries.

Function reference

First kind

Second kind

Modified, first kind

Modified, second kind

Hankel

Support

Quick start

use bessels, only: besselj0, besselk1, bk
real(BK) :: x(4)
x = [0.5_bk, 1.0_bk, 2.0_bk, 4.0_bk]
print *, besselj0(x) ! elemental: acts on the whole array
print *, besselk1(2.0_bk)
Definition bessels.f90:17
elemental real(bk) function, public besselj0(x)
Definition bessels.f90:67
elemental real(bk) function, public besselk1(x)
Definition bessels.f90:792

Building

The canonical build is fpm:

fpm test --profile release --flag "-march=native"

See the project README for the full benchmark table and the manual gfortran recipe.

Warning
The variable-order routines bessely(nu,x), besselh, hankelh1, and hankelh2 are validated for integer order \( \nu \) only. Non-integer order has known port bugs in the variable-order Y/Hankel paths and will return incorrect values. See roadmap item 07.

Roadmap

Still to come: real-order \( I_\nu,\; K_\nu \), spherical Bessels, and the Airy functions. See the implementation roadmap.