Skip to main content

NonZeroFactorization

Struct NonZeroFactorization 

Source
pub struct NonZeroFactorization<Factor, Power, Residual> {
    pub sign: NonZeroSign,
    pub factors: Vec<(Factor, Power)>,
    pub residual: Residual,
}
Expand description

Factorization of a nonzero integer or rational number.

Includes a sign.

§Invariant

The three fields together always describe the entire value:

value == sign * residual * product(factor ^ power)

The factorization routines are deliberately incomplete, because splitting a large cofactor is expensive. Whatever they did not decompose is in residual rather than dropped, so the identity above holds regardless of how they were tuned. Use Self::is_complete to find out whether the value was decomposed entirely.

Fields§

§sign: NonZeroSign

Whether the number is negative.

§factors: Vec<(Factor, Power)>

(factor, power) tuples.

These factors are often, but not necessarily, primes; they are all larger than 1. The factors should all be smaller than 64 bits and can have negative powers; that is, appear in the denominator. The powers can’t be zero, as this is a sparse representation.

When this field is empty, nothing was decomposed and the value is sign * residual. In particular, an empty list does not mean that the value is 1 or -1; that is the case only when the residual is one as well.

§residual: Residual

The part of the value that was not decomposed.

One exactly when the factors describe the entire value, see Self::is_complete. It is always positive; the sign of the value is in sign.

Implementations§

Source§

impl<Factor, Power, Residual: FactorizationResidual> NonZeroFactorization<Factor, Power, Residual>

Source

pub fn is_complete(&self) -> bool

Whether the value was decomposed entirely, that is, whether the residual is one.

When this is false, the factors describe only the part of the value that could be split off cheaply, and multiplying them together does not reproduce the value: the residual is the missing factor.

Trait Implementations§

Source§

impl<Factor: Clone, Power: Clone, Residual: Clone> Clone for NonZeroFactorization<Factor, Power, Residual>

Source§

fn clone(&self) -> NonZeroFactorization<Factor, Power, Residual>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Factor: Debug, Power: Debug, Residual: Debug> Debug for NonZeroFactorization<Factor, Power, Residual>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Factor: Eq, Power: Eq, Residual: Eq> Eq for NonZeroFactorization<Factor, Power, Residual>

Source§

impl<Factor: PartialEq, Power: PartialEq, Residual: PartialEq> PartialEq for NonZeroFactorization<Factor, Power, Residual>

Source§

fn eq(&self, other: &NonZeroFactorization<Factor, Power, Residual>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<Factor: PartialEq, Power: PartialEq, Residual: PartialEq> StructuralPartialEq for NonZeroFactorization<Factor, Power, Residual>

Auto Trait Implementations§

§

impl<Factor, Power, Residual> Freeze for NonZeroFactorization<Factor, Power, Residual>
where Vec<(Factor, Power)>: Freeze, Residual: Freeze,

§

impl<Factor, Power, Residual> RefUnwindSafe for NonZeroFactorization<Factor, Power, Residual>

§

impl<Factor, Power, Residual> Send for NonZeroFactorization<Factor, Power, Residual>
where Vec<(Factor, Power)>: Send, Residual: Send,

§

impl<Factor, Power, Residual> Sync for NonZeroFactorization<Factor, Power, Residual>
where Vec<(Factor, Power)>: Sync, Residual: Sync,

§

impl<Factor, Power, Residual> Unpin for NonZeroFactorization<Factor, Power, Residual>
where Vec<(Factor, Power)>: Unpin, Residual: Unpin,

§

impl<Factor, Power, Residual> UnsafeUnpin for NonZeroFactorization<Factor, Power, Residual>

§

impl<Factor, Power, Residual> UnwindSafe for NonZeroFactorization<Factor, Power, Residual>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.