pub trait CeilingRoot<POW> {
type Output;
// Required method
fn ceiling_root(self, pow: POW) -> Self::Output;
}Expand description
Finds the ceiling of the $n$th root of a number.
Required Associated Types§
Required Methods§
fn ceiling_root(self, pow: POW) -> Self::Output
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl CeilingRoot<u64> for i8
impl CeilingRoot<u64> for i8
Source§fn ceiling_root(self, exp: u64) -> i8
fn ceiling_root(self, exp: u64) -> i8
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = i8
Source§impl CeilingRoot<u64> for i16
impl CeilingRoot<u64> for i16
Source§fn ceiling_root(self, exp: u64) -> i16
fn ceiling_root(self, exp: u64) -> i16
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = i16
Source§impl CeilingRoot<u64> for i32
impl CeilingRoot<u64> for i32
Source§fn ceiling_root(self, exp: u64) -> i32
fn ceiling_root(self, exp: u64) -> i32
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = i32
Source§impl CeilingRoot<u64> for i64
impl CeilingRoot<u64> for i64
Source§fn ceiling_root(self, exp: u64) -> i64
fn ceiling_root(self, exp: u64) -> i64
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = i64
Source§impl CeilingRoot<u64> for i128
impl CeilingRoot<u64> for i128
Source§fn ceiling_root(self, exp: u64) -> i128
fn ceiling_root(self, exp: u64) -> i128
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = i128
Source§impl CeilingRoot<u64> for isize
impl CeilingRoot<u64> for isize
Source§fn ceiling_root(self, exp: u64) -> isize
fn ceiling_root(self, exp: u64) -> isize
Returns the ceiling of the $n$th root of an integer.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits():
constant for widths up to 64 bits and for exponents greater than 2, where a
floating-point approximation is refined with $O(1)$ adjustments; 128-bit square
roots (exp == 2) fall back to an $O(n)$ binary search.
§Panics
Panics if exp is zero, or if self is negative and exp is even.
§Examples
See here.
type Output = isize
Source§impl CeilingRoot<u64> for u8
impl CeilingRoot<u64> for u8
Source§impl CeilingRoot<u64> for u16
impl CeilingRoot<u64> for u16
Source§impl CeilingRoot<u64> for u32
impl CeilingRoot<u64> for u32
Source§fn ceiling_root(self, exp: u64) -> Self
fn ceiling_root(self, exp: u64) -> Self
Returns the ceiling of the $n$th root of a u32.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§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 CeilingRoot<u64> for u64
impl CeilingRoot<u64> for u64
Source§fn ceiling_root(self, exp: Self) -> Self
fn ceiling_root(self, exp: Self) -> Self
Returns the ceiling of the $n$th root of a u64.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§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 CeilingRoot<u64> for u128
impl CeilingRoot<u64> for u128
Source§fn ceiling_root(self, exp: u64) -> Self
fn ceiling_root(self, exp: u64) -> Self
Returns the ceiling of the $n$th root of a u128.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits(): constant
for widths up to 64 bits and for exponents greater than 2, where a floating-point
approximation is refined with $O(1)$ adjustments; 128-bit square roots (exp == 2) fall
back to an $O(n)$ binary search.
§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.