Skip to main content

RootAssignRem

Trait RootAssignRem 

Source
pub trait RootAssignRem<POW> {
    type RemOutput;

    // Required method
    fn root_assign_rem(&mut self, exp: POW) -> Self::RemOutput;
}
Expand description

Replaces a number with the floor of its $n$th root, returning the remainder.

Required Associated Types§

Required Methods§

Source

fn root_assign_rem(&mut self, exp: POW) -> Self::RemOutput

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl RootAssignRem<u64> for u8

Source§

fn root_assign_rem(&mut self, exp: u64) -> u8

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = u8

Source§

impl RootAssignRem<u64> for u16

Source§

fn root_assign_rem(&mut self, exp: u64) -> u16

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = u16

Source§

impl RootAssignRem<u64> for u32

Source§

fn root_assign_rem(&mut self, exp: u64) -> u32

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = u32

Source§

impl RootAssignRem<u64> for u64

Source§

fn root_assign_rem(&mut self, exp: u64) -> u64

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = u64

Source§

impl RootAssignRem<u64> for u128

Source§

fn root_assign_rem(&mut self, exp: u64) -> u128

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = u128

Source§

impl RootAssignRem<u64> for usize

Source§

fn root_assign_rem(&mut self, exp: u64) -> usize

Replaces an integer with the floor of its $n$th root, and returns the remainder (the difference between the original integer and the $n$th power of the floor).

$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,

$x \gets \lfloor\sqrt[n]{x}\rfloor$.

§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.

Source§

type RemOutput = usize

Implementors§