pub fn log2(value: f64) -> Result<f64, DomainError>
Expand description
Returns the base 2 logarithm of the number.
Domain: (0, INFINITY)
Codomain: (-INFINITY, INFINITY)
§Examples
use spinoso_math as math;
assert_eq!(math::log2(1.0), Ok(0.0));
assert_eq!(math::log2(2.0), Ok(1.0));
assert_eq!(math::log2(32768.0), Ok(15.0));
assert_eq!(math::log2(65536.0), Ok(16.0));
assert_eq!(math::log2(0.0), Ok(f64::NEG_INFINITY));
assert!(math::log2(-0.1).is_err());
assert!(matches!(math::log2(f64::NAN), Ok(result) if result.is_nan()));
§Errors
If the result of computing the logarithm is NAN
, a domain error is
returned.