use num_complex::Complex;
use crate::machine::BesselFloat;
#[inline]
pub(crate) fn zuchk<T: BesselFloat>(y: Complex<T>, ascle: T, tol: T) -> bool {
let wr = y.re.abs();
let wi = y.im.abs();
let st = wr.min(wi);
if st > ascle {
return false;
}
let ss = wr.max(wi);
ss < st / tol
}
#[cfg(test)]
mod tests {
use super::*;
use num_complex::Complex64;
#[test]
fn uchk_large_value_not_underflow() {
let y = Complex64::new(1.0, 1.0);
assert!(!zuchk(y, 1e-300, 1e-16));
}
#[test]
fn uchk_tiny_value_underflow() {
let y = Complex64::new(1e-310, 1e-320);
assert!(zuchk(y, 1e-300, 1e-16));
}
#[test]
fn uchk_mixed_no_underflow() {
let y = Complex64::new(1.0, 1e-10);
assert!(!zuchk(y, 1e-300, 1e-16));
}
#[test]
fn uchk_at_boundary() {
let ascle = 1e-300_f64;
let tol = 1e-16_f64;
let y = Complex64::new(1e-285, ascle);
assert!(zuchk(y, ascle, tol));
}
}