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§
Required Methods§
Sourcefn try_sqrt(self) -> Result<Self, <Self as Sqrt>::Error>
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.
Sourcefn sqrt(self) -> Self
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.