1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! `i0e`, `i1e` and `xlogy` over native-width `f64` vectors.
//!
//! `i0e` and `i1e` are ported from SciPy's [xsf] (BSD-3-Clause) commit
//! `39019a470a208221d55a587f0baa329c3d1054c5`, files `include/xsf/cephes/i0.h`,
//! `include/xsf/cephes/i1.h` and `include/xsf/cephes/chbevl.h` (Cephes, Stephen L. Moshier).
//! `xlogy` follows `include/xsf/log.h` and takes its logarithm from [`u10::log`]. The
//! coefficient tables are in [`crate::bessel`], which also holds the scalar reference.
//!
//! [xsf]: https://github.com/scipy/xsf
//!
//! # Accuracy
//!
//! These are not SLEEF tiers. The bounds are what the kernels reach against a high-precision
//! oracle (MPFR for `xlogy`, mpmath for `i0e`/`i1e`; see `tests/special.rs` and
//! `tests/data/`), asserted there with a margin:
//!
//! | function | bound | reference |
//! |---|---|---|
//! | [`i0e`] | 6 ULP (5.2 measured) | mpmath `besseli(0, x) * exp(-x)` |
//! | [`i1e`] | 8 ULP (6.9 measured) | mpmath `besseli(1, x) * exp(-x)` |
//! | [`xlogy`] | 1.5 ULP | exact `x * ln(y)` (MPFR) |
//!
//! The Chebyshev series are those of Cephes, whose own tables report `5.4e-16` (`i0e`) and
//! `2.0e-15` (`i1e`) peak relative error; the bound is a property of the series, not of the
//! vectorization.
//!
//! # Determinism
//!
//! All three are bit-identical on every SIMD level (`mul_add_precise` rounds once everywhere).
//! `i0e` and `i1e` are additionally bit-identical to the scalar reference in
//! [`crate::bessel`]; `xlogy` is not, because the scalar reference calls the platform `ln`.
use *;
/// `exp(-|x|) I0(x)`, exponentially scaled modified Bessel function of order zero.
///
/// The error bound of the returned value is `6 ULP`. Defined and finite for every `x`; it
/// never overflows, which is what the scaled form is for (`i0e(1e300) = 3.99e-151`, while
/// `I0(1e300)` is not representable). `i0e(+-inf) = 0`, `i0e(NaN) = NaN`.
/// `exp(-|x|) I1(x)`, exponentially scaled modified Bessel function of order one.
///
/// The error bound of the returned value is `8 ULP`. Odd in `x`, finite for every `x`,
/// `i1e(+-inf) = +-0`, `i1e(NaN) = NaN`.
/// `x * ln(y)`, defined as `0` when `x == 0` and `y` is not NaN.
///
/// The error bound of the returned value is `1.5 ULP`: the 1.0 ULP logarithm and one
/// multiplication. `xlogy(0, 0) = xlogy(0, inf) = 0`, `xlogy(0, NaN) = NaN`,
/// `xlogy(x > 0, 0) = -inf`, `xlogy(x < 0, 0) = +inf`, `xlogy(x, y < 0) = NaN`.
/// `32 / x - 2`, the Chebyshev argument of the `[8, inf)` series.
/// Clenshaw recurrence of Cephes `chbevl`, the same operation order as
/// [`crate::bessel::chbevl`].