pub trait RemovePower<RHS = Self> {
type Output;
// Required method
fn remove_power(self, other: RHS) -> (Self::Output, u64);
}Expand description
A trait for removing the largest power of a factor from a number, returning the reduced number and how many times the factor was removed.
Required Associated Types§
Required Methods§
fn remove_power(self, other: RHS) -> (Self::Output, u64)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl RemovePower for i8
impl RemovePower for i8
Source§fn remove_power(self, other: i8) -> (i8, u64)
fn remove_power(self, other: i8) -> (i8, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = i8
Source§impl RemovePower for i16
impl RemovePower for i16
Source§fn remove_power(self, other: i16) -> (i16, u64)
fn remove_power(self, other: i16) -> (i16, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = i16
Source§impl RemovePower for i32
impl RemovePower for i32
Source§fn remove_power(self, other: i32) -> (i32, u64)
fn remove_power(self, other: i32) -> (i32, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = i32
Source§impl RemovePower for i64
impl RemovePower for i64
Source§fn remove_power(self, other: i64) -> (i64, u64)
fn remove_power(self, other: i64) -> (i64, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = i64
Source§impl RemovePower for i128
impl RemovePower for i128
Source§fn remove_power(self, other: i128) -> (i128, u64)
fn remove_power(self, other: i128) -> (i128, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = i128
Source§impl RemovePower for isize
impl RemovePower for isize
Source§fn remove_power(self, other: isize) -> (isize, u64)
fn remove_power(self, other: isize) -> (isize, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = isize
Source§impl RemovePower for u8
impl RemovePower for u8
Source§fn remove_power(self, other: u8) -> (u8, u64)
fn remove_power(self, other: u8) -> (u8, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = u8
Source§impl RemovePower for u16
impl RemovePower for u16
Source§fn remove_power(self, other: u16) -> (u16, u64)
fn remove_power(self, other: u16) -> (u16, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = u16
Source§impl RemovePower for u32
impl RemovePower for u32
Source§fn remove_power(self, other: u32) -> (u32, u64)
fn remove_power(self, other: u32) -> (u32, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = u32
Source§impl RemovePower for u64
impl RemovePower for u64
Source§fn remove_power(self, other: u64) -> (u64, u64)
fn remove_power(self, other: u64) -> (u64, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = u64
Source§impl RemovePower for u128
impl RemovePower for u128
Source§fn remove_power(self, other: u128) -> (u128, u64)
fn remove_power(self, other: u128) -> (u128, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.
type Output = u128
Source§impl RemovePower for usize
impl RemovePower for usize
Source§fn remove_power(self, other: usize) -> (usize, u64)
fn remove_power(self, other: usize) -> (usize, u64)
Removes the largest power of a factor from a number, returning the reduced number together with the exponent of that power.
If $f^k$ is the largest power of other that divides self, this returns
$(\text{self}/f^k, k)$. The factor need not be prime. Zero is left alone, with an
exponent of 0, since every power of the factor divides it.
For signed types the quotient is the exact division by the signed power, so a negative factor raised to an odd power flips its sign.
§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():
each division by other, which is at least 2, removes at least one bit.
§Panics
Panics if other is 0 or 1, or, for signed types, -1: no largest power exists in
those cases.
§Examples
See here.