spinoso_math

Function log

Source
pub fn log(value: f64, base: Option<f64>) -> Result<f64, DomainError>
Expand description

Returns the logarithm of the number with respect to an arbitrary base.

Domain: (0, INFINITY)

Codomain: (-INFINITY, INFINITY)

§Examples

use spinoso_math as math;
assert_eq!(math::log(1.0, None), Ok(0.0));
assert_eq!(math::log(E, None), Ok(1.0));
assert_eq!(math::log(64.0, Some(4.0)), Ok(3.0));

assert_eq!(math::log(0.0, None), Ok(f64::NEG_INFINITY));
assert!(math::log(-0.1, None).is_err());

assert!(matches!(math::log(f64::NAN, None), Ok(result) if result.is_nan()));

§Errors

If the given arbitrary base is NAN, a domain error is returned.

If the result of computing the logarithm is NAN, a domain error is returned.