Sqrt

Trait Sqrt 

Source
pub trait Sqrt: TryNew {
    type Error: Debug;

    // Required methods
    fn try_sqrt(self) -> Result<Self, <Self as Sqrt>::Error>;
    fn sqrt(self) -> Self;
}
Expand description

This trait provides the interface for the function used to compute the square root of a number.

Required Associated Types§

Source

type Error: Debug

The error type that can be returned by the try_sqrt method.

Required Methods§

Source

fn try_sqrt(self) -> Result<Self, <Self as Sqrt>::Error>

Computes the square root of self, checking the input and output values for validity.

§Validity
  • For the square root of a real number:
    • the input value is valid if is finite, positive and normal;
    • the output value is valid if is finite and normal.
  • For the square root of a complex number:
    • The input and output values are valid if they are finite and normal.
§Returns
  • Ok(self) if the square root computation is successful and the input and output values are valid.
  • Err(Self::Error) if the input or output values are invalid.
Source

fn sqrt(self) -> Self

Computes the square root of self, with no checks (in Release mode) on the validity of the input and output values.

In Debug mode, this function internally calls the function Sqrt::try_sqrt() and a panic! is raised if the function returns an error.

§Panics

This function will panic in Debug mode if the input or output values are invalid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Sqrt for f64

Implementation of the Sqrt trait for f64.

Source§

type Error = SqrtRealErrors<Native64>

Source§

fn try_sqrt(self) -> Result<Self, <Self as Sqrt>::Error>

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for Complex<f64>

Implementation of the Sqrt trait for Complex.

Source§

type Error = SqrtComplexErrors<Native64>

Source§

fn try_sqrt(self) -> Result<Self, <Self as Sqrt>::Error>

Source§

fn sqrt(self) -> Self

Implementors§