lib_jsl_special_functions/
hankel.rs1use crate::bessel_functions_fractional::bessel_jy;
7use num_complex::Complex;
8
9type C = Complex<f64>;
10
11pub fn hankel1(v: f64, x: f64) -> C {
15 let (j, y) = bessel_jy(v, x);
16 C::new(j, y)
17}
18
19pub fn hankel2(v: f64, x: f64) -> C {
21 let (j, y) = bessel_jy(v, x);
22 C::new(j, -y)
23}
24pub fn hankel1e(v: f64, x: f64) -> C {
28 hankel1(v, x) * C::from_polar(1.0, -x)
29}
30
31pub fn hankel2e(v: f64, x: f64) -> C {
33 hankel2(v, x) * C::from_polar(1.0, x)
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39 use std::f64::consts::PI;
40
41 #[test]
42 fn half_order_closed_form_and_conjugacy() {
43 for &x in &[0.5, 2.0, 9.0, 40.0] {
45 let h = hankel1(0.5, x);
46 let want = C::new(0.0, -(2.0 / (PI * x)).sqrt()) * C::from_polar(1.0, x);
47 assert!((h - want).norm() < 1e-13 * want.norm(), "{x}");
48 assert_eq!(hankel2(0.5, x), h.conj());
49 assert!((hankel1e(0.5, x).norm() - want.norm()).abs() < 1e-14);
50 }
51 assert!(hankel1(0.0, -1.0).re.is_nan());
52 }
53}