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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! # Bessel Zeros
//!
//! A crate for finding the zeros of the Bessel functions.
//!
//! This crate uses the routine described in:
//! "An Algorithm with ALGOL 60 Program for the Computation of the
//! zeros of the Ordinary Bessel Functions and those of their
//! Derivatives".
//! N. M. Temme
//! Journal of Computational Physics, 32, 270-279 (1979)
//!
//! This crate is inspired by (via several intermediate steps)
//! Adam Wyatt's Matlab version of this code.
//!
//! ## Backends
//!
//! Two backends are available:
//!
//! | Backend | Module / functions | Order type | Speed |
//! |---|---|---|---|
//! | AMOS (`amos-bessel-rs`) | crate root | any `f64`-compatible | slower |
//! | real-bessel | [`fast`] sub-module | `i32` only | faster |
//!
//! ## Primary API (AMOS backend — any real order)
//!
//! - [`bessel_zeros_j`]
//! - [`bessel_zeros_y`]
//! - [`bessel_zeros_jp`]
//! - [`bessel_zeros_yp`]
//! - [`bessel_zeros`] — lower-level, accepts a [`BesselFunType`] and custom precision
//!
//! ## Fast API (real-bessel backend — integer orders only)
//!
//! Use the [`fast`] sub-module for the same functions with integer orders:
//!
//! ```rust
//! use bessel_zeros::fast;
//!
//! let zeros = fast::bessel_zeros_j(0, 5);
//! assert_eq!(zeros.len(), 5);
//! assert!((zeros[0] - 2.40482555769577).abs() < 1e-10);
//! ```
//!
//! ## Example (AMOS backend, non-integer order)
//!
//! ```rust
//! use bessel_zeros::bessel_zeros_j;
//!
//! let zeros = bessel_zeros_j(0.5_f64, 5);
//! assert_eq!(zeros.len(), 5);
//! ```
pub
pub
use bessel_zeros_impl;
use AmosBackend;
/// Default relative error tolerance used by the convenience functions
/// ([`bessel_zeros_j`], [`bessel_zeros_y`], [`bessel_zeros_jp`], [`bessel_zeros_yp`]).
/// Pass a custom value to [`bessel_zeros`] if you need different precision.
pub const DEFAULT_PRECISION: f64 = 1e-14;
/// The type of Bessel function of which to find the zeros.
/// Calculates the zeros of the Bessel function of the given kind and `order`.
///
/// Note: this general-purpose AMOS-backed function is only defined for non-negative
/// `order` (`order >= 0.0`). If you need zeros for a negative integer order, use the
/// integer-only [`fast::bessel_zeros`] function instead, or pass the absolute value
/// of the order (since J₋ₙ and Y₋ₙ have identical zeros to their positive counterparts).
///
/// # Arguments the AMOS backend; `order` can be any type that converts to `f64`
/// (e.g. `f64`, `f32`, `i32`, `u32`).
/// Finds the first `n_zeros` zeros of the Bessel function of the second kind Yv(x).
///
/// Uses the AMOS backend; `order` can be any type that converts to `f64`.
/// Finds the first `n_zeros` zeros of the derivative of Jv(x).
///
/// Uses the AMOS backend; `order` can be any type that converts to `f64`.
/// Finds the first `n_zeros` zeros of the derivative of Yv(x).
///
/// Uses the AMOS backend; `order` can be any type that converts to `f64`.
/// Finds the first `n_zeros` zeros of the specified Bessel function.
///
/// Uses the AMOS backend, so `order` may be any real value (not just integer).
///
/// # Arguments
///
/// * `func_type` - Which Bessel function (J, Y, J', Y').
/// * `order` - The order (must be ≥ 0); any type convertible to `f64`.
/// * `n_zeros` - Number of zeros to return.
/// * `precision` - Relative error tolerance on each root.
/// Fast Bessel zero computation using the `real-bessel` backend.
///
/// This module mirrors the crate-root API ([`bessel_zeros_j`], [`bessel_zeros_y`],
/// [`bessel_zeros_jp`], [`bessel_zeros_yp`], [`bessel_zeros`]) but uses the
/// [`real_bessel`] crate internally. It is significantly faster than the AMOS
/// backend but is restricted to **integer orders** (`i32`).
///
/// For non-integer orders use the crate-root functions directly.
///
/// # Example
///
/// ```rust
/// use bessel_zeros::fast;
///
/// let zeros = fast::bessel_zeros_j(0, 5);
/// assert!((zeros[0] - 2.40482555769577).abs() < 1e-10);
/// ```