pub trait ExpM1 {
// Required method
fn exp_m1(self) -> Self;
}Expand description
Trait for computing exp(x) - 1 with high precision for small values.
This trait provides the exp_m1 function, which computes e^x - 1 more accurately
than exp(x) - 1 when x is close to zero. This avoids catastrophic cancellation
that occurs when subtracting two nearly equal numbers.
§Mathematical Background
For small values of x, computing exp(x) - 1 directly can lose precision because
exp(x) is close to 1. The exp_m1 function uses alternative algorithms (such as
Taylor series) that maintain accuracy in this regime.
§Examples
use num_valid::functions::ExpM1;
let x = 1e-10f64;
let result = ExpM1::exp_m1(x);
// More accurate than: x.exp() - 1.0
assert!((result - x).abs() < 1e-15);Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.