Shared Rust kernels

ported/excel_numeric/x87_chains

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

pow2_positive · 7 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// `2^t` for an extended `t >= 0`: `FRNDINT`, `F2XM1` of the fraction, `+1`, `FSCALE`.
fn pow2_positive<F: Fpu>(t: &Ext80) -> Ext80 {
    let whole = F::rndint(t, CW);
    let fraction = F::sub(t, &whole, CW);
    let m = F::add(&F::f2xm1(&fraction, CW), &ext_one(), CW);
    F::scale(&m, &whole, CW)
}

Used by 45 functions.

pow2 · 9 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// `2^t` for an extended `t`; a negative `t` as the extended reciprocal of `2^-t` (measured: the
/// EXP witnesses of small negative arguments are the reciprocals' roundings).
fn pow2<F: Fpu>(t: &Ext80) -> Ext80 {
    if t.0[9] & 0x80 != 0 {
        F::div(&ext_one(), &pow2_positive::<F>(&ext_chs(t, CW)), CW)
    } else {
        pow2_positive::<F>(t)
    }
}

Used by 45 functions.

exp_ext · 4 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// `e^t` for an extended `t`: `2^(t log2 e)`.
fn exp_ext<F: Fpu>(t: &Ext80) -> Ext80 {
    pow2::<F>(&F::mul(t, &ext_l2e(), CW))
}

Used by 45 functions.

exp_with · 12 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
fn exp_with<F: Fpu>(x: f64, cw: u16) -> f64 {
    if x.is_nan() {
        return x;
    }
    if x == f64::INFINITY {
        return x;
    }
    if x == f64::NEG_INFINITY {
        return 0.0;
    }
    F::store(&exp_ext::<F>(&load(x)), cw)
}

Used by 45 functions.

excel_exp · 4 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// Excel's `EXP`.
pub(crate) fn excel_exp(x: f64) -> f64 {
    exp_with::<Native>(x, CW)
}

Used by 45 functions.

log_with · 19 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// `constant * log2 x` by `FYL2X`, with the logarithm's special values.
fn log_with<F: Fpu>(x: f64, constant: &Ext80) -> f64 {
    if x.is_nan() {
        return x;
    }
    if x < 0.0 {
        return f64::NAN;
    }
    if x == 0.0 {
        return f64::NEG_INFINITY;
    }
    if x == f64::INFINITY {
        return x;
    }
    if x == 1.0 {
        return 0.0;
    }
    F::store(&F::fyl2x(constant, &load(x), CW), CW)
}

Used by 45 functions.

excel_log · 4 lines · calc-func/src/ported/excel_numeric/x87_chains.rs on GitHub
/// Excel's `LN`.
pub(crate) fn excel_log(x: f64) -> f64 {
    log_with::<Native>(x, &ext_ln2())
}

Used by 45 functions.