expm1_simd

Function expm1_simd 

Source
pub fn expm1_simd<F>(a: &ArrayView1<'_, F>) -> Array1<F>
where F: Float + SimdUnifiedOps,
Expand description

SIMD-accelerated numerically stable exp(x) - 1

Computes exp(x) - 1 accurately for small x values where the direct calculation exp(x) - 1 would suffer from catastrophic cancellation. For |x| < 1e-10, the result is approximately x (Taylor expansion).

§Arguments

  • a - Input values

§Returns

Array of exp(x) - 1 values

§Examples

use scirs2_core::ndarray::{array, Array1};
use scirs2_core::ndarray_ext::elementwise::expm1_simd;

let x = array![0.0_f64, 1e-15, 1.0, -1.0];

let result = expm1_simd::<f64>(&x.view());
// exp(0) - 1 = 0
assert!((result[0] - 0.0).abs() < 1e-14);
// For small x: exp(x) - 1 ≈ x
assert!((result[1] - 1e-15).abs() < 1e-29);
// exp(1) - 1 ≈ 1.718
assert!((result[2] - (1.0_f64.exp() - 1.0)).abs() < 1e-14);

§Use Cases

  • Financial calculations (compound interest for small rates)
  • Numerical integration (avoiding cancellation errors)
  • Statistical distributions (Poisson, exponential)
  • Machine learning (softplus: log(1 + exp(x)))