Trait malachite_base::num::arithmetic::traits::CheckedRoot
source · pub trait CheckedRoot<POW> {
type Output;
// Required method
fn checked_root(self, pow: POW) -> Option<Self::Output>;
}
Expand description
Finds the $n$th root of a number, returning None
if it is not a perfect $n$th power.
Required Associated Types§
Required Methods§
fn checked_root(self, pow: POW) -> Option<Self::Output>
Implementations on Foreign Types§
source§impl CheckedRoot<u64> for i8
impl CheckedRoot<u64> for i8
source§fn checked_root(self, exp: u64) -> Option<i8>
fn checked_root(self, exp: u64) -> Option<i8>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = i8
source§impl CheckedRoot<u64> for i16
impl CheckedRoot<u64> for i16
source§fn checked_root(self, exp: u64) -> Option<i16>
fn checked_root(self, exp: u64) -> Option<i16>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = i16
source§impl CheckedRoot<u64> for i32
impl CheckedRoot<u64> for i32
source§fn checked_root(self, exp: u64) -> Option<i32>
fn checked_root(self, exp: u64) -> Option<i32>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = i32
source§impl CheckedRoot<u64> for i64
impl CheckedRoot<u64> for i64
source§fn checked_root(self, exp: u64) -> Option<i64>
fn checked_root(self, exp: u64) -> Option<i64>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = i64
source§impl CheckedRoot<u64> for i128
impl CheckedRoot<u64> for i128
source§fn checked_root(self, exp: u64) -> Option<i128>
fn checked_root(self, exp: u64) -> Option<i128>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = i128
source§impl CheckedRoot<u64> for isize
impl CheckedRoot<u64> for isize
source§fn checked_root(self, exp: u64) -> Option<isize>
fn checked_root(self, exp: u64) -> Option<isize>
Returns the the $n$th root of an integer, or None
if the integer is not a perfect
$n$th power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero, or if self
is negative and exp
is even.
§Examples
See here.
type Output = isize
source§impl CheckedRoot<u64> for u8
impl CheckedRoot<u64> for u8
source§fn checked_root(self, exp: u64) -> Option<u8>
fn checked_root(self, exp: u64) -> Option<u8>
Returns the the $n$th root of a u8
, or None
if the u8
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
The u8
implementation uses lookup tables.
type Output = u8
source§impl CheckedRoot<u64> for u16
impl CheckedRoot<u64> for u16
source§fn checked_root(self, exp: u64) -> Option<u16>
fn checked_root(self, exp: u64) -> Option<u16>
Returns the the $n$th root of a u16
, or None
if the u16
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
type Output = u16
source§impl CheckedRoot<u64> for u32
impl CheckedRoot<u64> for u32
source§fn checked_root(self, exp: u64) -> Option<u32>
fn checked_root(self, exp: u64) -> Option<u32>
Returns the the $n$th root of a u32
, or None
if the u32
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
For cube roots, the u32
implementation uses a piecewise Chebyshev approximation. For
other roots, it uses Newton’s method. In both implementations, the result of these
approximations is adjusted afterwards to account for error.
type Output = u32
source§impl CheckedRoot<u64> for u64
impl CheckedRoot<u64> for u64
source§fn checked_root(self, exp: u64) -> Option<u64>
fn checked_root(self, exp: u64) -> Option<u64>
Returns the the $n$th root of a u64
, or None
if the u64
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
For cube roots, the u64
implementation uses a piecewise Chebyshev approximation. For
other roots, it uses Newton’s method. In both implementations, the result of these
approximations is adjusted afterwards to account for error.
type Output = u64
source§impl CheckedRoot<u64> for u128
impl CheckedRoot<u64> for u128
source§fn checked_root(self, exp: u64) -> Option<u128>
fn checked_root(self, exp: u64) -> Option<u128>
Returns the the $n$th root of a u128
, or None
if the u128
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
The u128
implementation computes the root using floating-point arithmetic. The
approximate result is adjusted afterwards to account for error.
type Output = u128
source§impl CheckedRoot<u64> for usize
impl CheckedRoot<u64> for usize
source§fn checked_root(self, exp: u64) -> Option<usize>
fn checked_root(self, exp: u64) -> Option<usize>
Returns the the $n$th root of a usize
, or None
if the usize
is not a perfect $n$th
power.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
The usize
implementation calls the u32
or u64
implementations.