use crate::ffi;
pub fn chebyshev_t(n: u32, x: f64) -> f64 {
unsafe { ffi::math_chebyshev_t(n, x) }
}
#[doc(alias = "chebyshev_t_derivative")]
pub fn chebyshev_t_prime(n: u32, x: f64) -> f64 {
unsafe { ffi::math_chebyshev_t_prime(n, x) }
}
pub fn chebyshev_u(n: u32, x: f64) -> f64 {
unsafe { ffi::math_chebyshev_u(n, x) }
}
#[inline(always)]
#[allow(non_snake_case)]
#[doc(alias = "chebyshev_t_next")]
#[doc(alias = "chebyshev_u_next")]
pub fn chebyshev_next(x: f64, Tn: f64, Tn_prev: f64) -> f64 {
2.0 * x * Tn - Tn_prev
}
#[cfg(test)]
mod test {
use crate::math::{chebyshev_t, chebyshev_t_prime, chebyshev_u};
#[test]
fn test_chebyshev_t() {
assert_relative_eq!(chebyshev_t(0, 0.5), 1.0);
assert_relative_eq!(chebyshev_t(1, 0.5), 0.5);
assert_relative_eq!(chebyshev_t(2, 0.5), -0.5);
assert_relative_eq!(chebyshev_t(3, 0.5), -1.0);
assert_relative_eq!(chebyshev_t(4, 0.5), -0.5);
assert_relative_eq!(chebyshev_t(5, 0.5), 0.5);
assert_relative_eq!(chebyshev_t(6, 0.5), 1.0);
}
#[test]
fn test_chebyshev_t_prime() {
assert_relative_eq!(chebyshev_t_prime(0, 0.5), 0.0);
assert_relative_eq!(chebyshev_t_prime(1, 0.5), 1.0);
assert_relative_eq!(chebyshev_t_prime(2, 0.5), 2.0);
assert_relative_eq!(chebyshev_t_prime(3, 0.5), 0.0);
assert_relative_eq!(chebyshev_t_prime(4, 0.5), -4.0);
assert_relative_eq!(chebyshev_t_prime(5, 0.5), -5.0);
assert_relative_eq!(chebyshev_t_prime(6, 0.5), 0.0);
}
#[test]
fn test_chebyshev_u() {
assert_relative_eq!(chebyshev_u(0, 0.5), 1.0);
assert_relative_eq!(chebyshev_u(1, 0.5), 1.0);
assert_relative_eq!(chebyshev_u(2, 0.5), 0.0);
assert_relative_eq!(chebyshev_u(3, 0.5), -1.0);
assert_relative_eq!(chebyshev_u(4, 0.5), -1.0);
assert_relative_eq!(chebyshev_u(5, 0.5), 0.0);
assert_relative_eq!(chebyshev_u(6, 0.5), 1.0);
}
}