pub fn safe_log(x: f64) -> StatsResult<f64>Expand description
Computes the natural logarithm of x, handling edge cases safely.
§Arguments
x- The input number.
§Returns
StatsResult<f64>- The natural logarithm of x, or an error if x is invalid.
§Errors
Returns StatsError::InvalidInput if x is less than or equal to 0.
§Examples
use rs_stats::utils::safe_log;
let result = safe_log(2.71828).unwrap();
assert!((result - 1.0).abs() < 1e-5);
// Error case
let result = safe_log(0.0);
assert!(result.is_err());