Function fixed_sqrt

Source
fn fixed_sqrt<F: FixedPointNumber>(x: &F) -> Option<F>
where F::Inner: From<u8>,
Expand description

Computes the square root of a fixed-point number [FixedPointNumber] x.

Uses the Newton-Raphson method internally via fixed_sqrt_newton for the general case, with exact fast paths for the common values 0 and 1.

§Domain

Defined only for x >= 0. Returns None for negative inputs, as the square root of a negative number is not real-valued.

§Arguments

  • x - The fixed-point number to compute the square root of.

§Returns

  • Some(sqrt(x)) for x >= 0
  • None for x < 0

§Examples

let x = FixedU64::saturating_from_integer(4);
assert_eq!(fixed_sqrt(&x), Some(FixedU64::saturating_from_integer(2)));

let x = FixedI64::saturating_from_integer(-1);
assert_eq!(fixed_sqrt(&x), None);