Skip to content

Precision guide

Most Nautilus numerical functions operate in f32 (IEEE 754 single precision), providing approximately 6-7 significant decimal digits. Nautilus.Special functions accept f32 or f64 inputs. Nautilus.Rolling uses f64 series.

The table reports f32 errors. Improvements from f64 vary by function. Six functions (gamma, log_gamma, beta, lbeta, ellipk, and ellipe) are limited by f32 rounding rather than by their own coefficients, so at f64 their errors are much smaller. The other approximations improve by less, depending on the function and argument. Measure the argument range your calculation uses.

Treat the table as an f32 guide. It has no figure for beta or lbeta, and bessel_y1 has an absolute error of about 1.2e-4 at either dtype just below its large-x seam at x = 7.5, well away from any zero.

The measured dtype differences include:

  • erf is capped by Abramowitz & Stegun 7.1.26's own 1.5e-7 error. At x = 0.5 an f64 erf measures 1.385e-7 against an f32 erf's 1.861e-7; over the whole range the maxima are 1.3884e-7 and 4.438e-7.
  • airy_ai and airy_bi above x = 5 use only the leading asymptotic term and gain nothing from f64 there; the two dtypes agree to three digits. Below x = 5 f64 is far better.
  • f32 erfc returns exactly 0 from about x = 3.92 onward; f64 returns 1.546e-8 at x = 4 and remains nonzero to about x = 5.5. Its relative error is still 2.8e-3 at x = 4: subtracting erf(x) from 1 cancels nearly equal values while retaining erf's absolute approximation error. A nonzero f64 tail is not necessarily accurate to three significant digits.
FamilyError guide (relative unless marked absolute)Notes
erf~1e-7Horner rational approximation
erfcsame absolute error as erf1 - erf(x), so relative error grows in the upper tail
erfinv~1e-8Acklam rational approximation via norminv
gamma~1e-7Lanczos (g=7) with reflection
log_gamma~1e-9Lanczos (g=7) with reflection
digamma~1e-7Recurrence + asymptotic (x >= 6)
trigamma~1e-6Recurrence + asymptotic (x >= 6)
ellipk, ellipe~1e-8AGM recurrence (quadratic convergence)
bessel_j0, j1Use absolute comparisons near zerosRational polynomial + large-x trig
bessel_y0Use absolute comparisons near zerosRational + log-singularity
bessel_y1~1.2e-4 absolute at x ≈ 7.4Large-x branch from x = 7.5; use absolute comparisons near zeros
bessel_i0, i1f32Polynomial + asymptotic, crossover 3.75
bessel_k0, k1f32Polynomial/log + asymptotic, crossover 2.0
airy_ai, airy_bif32 for |x| <= 5See large-negative-x note below
Distribution CDFs~1e-5 to 1e-7Depends on underlying special functions
normal_cdf~1e-7Delegates to erf
normal_inv_cdf~1e-7Acklam rational via erfinv

For bessel_j0, bessel_j1, bessel_y0, and bessel_y1, a small absolute error can produce a large relative error near a zero: relative error divides the absolute difference by the reference value's magnitude. At an exact zero, that ratio is undefined. Compare absolute differences there and calibrate tolerances against a reference over the arguments your calculation uses. The bessel_y1 measurement at x ≈ 7.4 describes its approximation-branch boundary, not an error bound near zeros or across the full domain.

airy_ai uses a power series for |x| <= 5 and an exponential asymptotic for x > 5. For large negative x, only the power series is available (no asymptotic oscillatory branch is implemented). The function enters an oscillatory regime for x < 0 and the power series degrades for |x| much larger than 5. airy_bi has the same limitation but is less affected because it grows exponentially for positive x where the asymptotic branch covers it.

Cancellation in subtraction-heavy expressions

Section titled “Cancellation in subtraction-heavy expressions”

Any computation involving subtraction of nearly-equal f32 values will suffer catastrophic cancellation. This affects:

  • cosine_distance when vectors are nearly parallel (1 - sim near 0)
  • variance_vec for data with very small variance relative to the mean
  • gamma_cdf for extreme shape/scale ratios

When f32 precision is insufficient in Nautilus.Special, call it at f64 directly. Its functions have an explicit {f32, f64} dtype bound. Read the caveats above first, because several of them are coefficient-limited rather than dtype-limited. The distribution, linear-algebra, and solver APIs described here are f32-only.

Nautilus.Special does not admit f16 or bf16; these calls are type errors.

SciPy typically computes in f64, while most Nautilus functions return f32. Compare values at the precision and inputs appropriate to the calculation; the functions' approximations have different numerical domains.