pub trait Ln1p {
// Required method
fn ln_1p(self) -> Self;
}Expand description
Trait for computing ln(1 + x) with high precision for small values.
This trait provides the ln_1p function, which computes ln(1 + x) more accurately
than ln(1.0 + x) when x is close to zero. This avoids precision loss from adding
a small number to 1 and then taking the logarithm.
§Mathematical Background
For small values of x, computing ln(1 + x) directly loses precision because
1 + x rounds to 1 in floating-point arithmetic. The ln_1p function uses
alternative algorithms (such as Taylor series) that maintain accuracy for small x.
§Examples
use num_valid::functions::Ln1p;
let x = 1e-10f64;
let result = Ln1p::ln_1p(x);
// More accurate than: (1.0 + x).ln()
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.