fn complex_sqrt<F: FixedPointNumber>(x: &F) -> Option<Complex<F>>Expand description
Computes the principal square root of a fixed-point number, returning
a Complex result.
Unlike fixed_sqrt, this function is defined for all inputs including
negative numbers. For negative inputs, the result is a purely imaginary
number representing the principal square root in the complex plane.
Internally delegates to fixed_sqrt_newton for the real square root
computation, which is only valid for non-negative inputs. The sign of x
is handled here before dispatching.
§Domain
Defined for all fixed-point values. Never returns None.
§Arguments
x- The fixed-point number to compute the complex square root of.
§Returns
| Input | Result |
|---|---|
x > 0 | sqrt(x) + 0i |
x = 0 | 0 + 0i |
x < 0 | `0 + sqrt( |
§Note
On unsigned types (FixedU64, FixedU128), negative values are not
representable, so the imaginary branch is never reached. Only the real
and zero branches apply.
§Examples
ⓘ
// Positive input - purely real result
let x = FixedI64::saturating_from_integer(4);
assert_eq!(complex_sqrt(&x), Some(Complex { real: FixedI64::saturating_from_integer(2), imgn: FixedI64::zero() }));
// Negative input - purely imaginary result
let x = FixedI64::saturating_from_integer(-4);
assert_eq!(complex_sqrt(&x), Some(Complex { real: FixedI64::zero(), imgn: FixedI64::saturating_from_integer(2) }));