Shared Rust kernels
ported/bessel_rational
All modules · quoted at commit 9e1884369a67 of DnaCalc/DnaCalc. Comments are the source's own.
polynomial · 3 lines · calc-func/src/ported/bessel_rational.rs on GitHubfn polynomial(x: f64, coefficients: &[f64]) -> f64 {
polynomial_with(x, coefficients, |a, b| a * b, |a, b| a + b)
}
Used by 2 functions.
polynomial_with · 12 lines · calc-func/src/ported/bessel_rational.rs on GitHubfn polynomial_with(
x: f64,
coefficients: &[f64],
multiply: impl Fn(f64, f64) -> f64,
add: impl Fn(f64, f64) -> f64,
) -> f64 {
let mut value = *coefficients.last().unwrap();
for &coefficient in coefficients[..coefficients.len() - 1].iter().rev() {
value = add(multiply(x, value), coefficient);
}
value
}
Used by 3 functions.
j0 · 4 lines · calc-func/src/ported/bessel_rational.rs on GitHubpub(super) fn j0(x: f64) -> f64 {
let square = x * x;
polynomial(square, J0_NUM) / polynomial(square, J0_DEN)
}
Used by 2 functions.
j1 · 4 lines · calc-func/src/ported/bessel_rational.rs on GitHubpub(super) fn j1(x: f64) -> f64 {
let square = x * x;
(x * polynomial(square, J1_NUM)) / polynomial(square, J1_DEN)
}
Used by 2 functions.