Shared Rust kernels

ported/asin

All modules · quoted at commit 9e1884369a67 of DnaCalc/DnaCalc. Comments are the source's own.

asin_kernel · 18 lines · calc-func/src/ported/asin.rs on GitHub
/// ASIN; #NUM! outside -1..1.
pub fn asin_kernel(n: f64) -> Result<f64, WorksheetErrorCode> {
    if !(-1.0..=1.0).contains(&n) {
        return Err(WorksheetErrorCode::Num);
    }
    // The second factor reuses the published difference. Computing 1+n
    // independently loses the observed asymmetry for negative inputs.
    // Each arithmetic primitive publishes binary64 after RN64 evaluation.
    let t = excel_x87_sub(1.0, n);
    let u = excel_x87_sub(2.0, t);
    let root = excel_sqrt_staged(excel_x87_mul(t, u));
    let angle = excel_atan_reduced(excel_x87_div(n, root));
    Ok(if angle.abs() < f64::MIN_POSITIVE {
        0.0
    } else {
        angle
    })
}

Used by 2 functions.