Trait malachite_base::num::arithmetic::traits::RootRem
source · pub trait RootRem<POW> {
type RootOutput;
type RemOutput;
// Required method
fn root_rem(self, exp: POW) -> (Self::RootOutput, Self::RemOutput);
}
Expand description
Finds the floor of the $n$th root of a number, returning both the root and the remainder.
Required Associated Types§
type RootOutput
type RemOutput
Required Methods§
fn root_rem(self, exp: POW) -> (Self::RootOutput, Self::RemOutput)
Implementations on Foreign Types§
source§impl RootRem<u64> for u8
impl RootRem<u64> for u8
source§fn root_rem(self, exp: u64) -> (u8, u8)
fn root_rem(self, exp: u64) -> (u8, u8)
Returns the floor of the $n$th root of a u8
, and the remainder (the difference between
the u8
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^2)$.
§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 RootOutput = u8
type RemOutput = u8
source§impl RootRem<u64> for u16
impl RootRem<u64> for u16
source§fn root_rem(self, exp: u64) -> (u16, u16)
fn root_rem(self, exp: u64) -> (u16, u16)
Returns the floor of the $n$th root of a u16
, and the remainder (the difference between
the u16
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^2)$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if exp
is zero.
§Examples
See here.
§Notes
type RootOutput = u16
type RemOutput = u16
source§impl RootRem<u64> for u32
impl RootRem<u64> for u32
source§fn root_rem(self, exp: u64) -> (u32, u32)
fn root_rem(self, exp: u64) -> (u32, u32)
Returns the floor of the $n$th root of a u32
, and the remainder (the difference between
the u32
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^2)$.
§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 RootOutput = u32
type RemOutput = u32
source§impl RootRem<u64> for u64
impl RootRem<u64> for u64
source§fn root_rem(self, exp: u64) -> (u64, u64)
fn root_rem(self, exp: u64) -> (u64, u64)
Returns the floor of the $n$th root of a u64
, and the remainder (the difference between
the u64
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^2)$.
§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 RootOutput = u64
type RemOutput = u64
source§impl RootRem<u64> for u128
impl RootRem<u64> for u128
source§fn root_rem(self, exp: u64) -> (u128, u128)
fn root_rem(self, exp: u64) -> (u128, u128)
Returns the floor of the $n$th root of a u128
, and the remainder (the difference between
the u128
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^n)$.
§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 RootOutput = u128
type RemOutput = u128
source§impl RootRem<u64> for usize
impl RootRem<u64> for usize
source§fn root_rem(self, exp: u64) -> (usize, usize)
fn root_rem(self, exp: u64) -> (usize, usize)
Returns the floor of the $n$th root of a usize
, and the remainder (the difference
between the usize
and the $n$th power of the floor).
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^2)$.
§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.