[−][src]Trait bigbit::DivRem
Combined division and remainder operations.
The usual process for getting both the division result and the remainder is performing both operations sequentially, since most programming languages, including Rust, do not provide an interface for introspecting the remainder acquired after dividing with the designated CPU instructions (LLVM will, however, optimize the two operations into one, given that optimizations are actually enabled). With BitBit numbers, however, division is implemented iteratively, without harware acceleration, i.e. the CPU doesn't assist the process by providing special instructions to perform the operations.
The current division implementation simply drops the remainder, which has the cost of deallocating the coefficient/LinkedByte
sequence, only to allocate and calculate it yet again. By using this trait, you ensure that nothing is ever dropped during division and that you get both the quotient and remainder the fastest way possible.
Associated Types
Loading content...Required methods
fn div_rem(self, rhs: Rhs) -> (Self::Quotient, Self::Remainder)
Performs combined quotient and remainder calculation.
The first element is the quotient, and the second one is the remainder.
Implementors
impl DivRem<LBNum> for LBNum
[src]
type Quotient = Self
type Remainder = Self
fn div_rem(self, rhs: Self) -> (Self, Self)
[src]
Performs combined integer division and remainder calculation.
Panics
Dividing by 0 triggers an immediate panic.
impl DivRem<u8> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.
fn div_rem(self, rhs: u8) -> (Self, Self)
[src]
impl DivRem<u16> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.
fn div_rem(self, rhs: u16) -> (Self, Self)
[src]
impl DivRem<u32> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.
fn div_rem(self, rhs: u32) -> (Self, Self)
[src]
impl DivRem<u64> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.
fn div_rem(self, rhs: u64) -> (Self, Self)
[src]
impl DivRem<u128> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.
fn div_rem(self, rhs: u128) -> (Self, Self)
[src]
impl DivRem<usize> for LBNum
[src]
type Quotient = Self
type Remainder = Self
The remainder type.
The reason why this is Self
instead of the type of the divisor is that the remainder as available when the division is finished is still of type LBNum
: it's never converted to the divisor type. As a result, the remainder is returned as-is to avoid situations when the remainder is required to be an LBNum
yet has been converted to the divisor type, which would require converting it back into LBNum
, which would require another allocation and performing the conversion process itself and would also waste the previous buffer.