Skip to main content

Natural

Enum Natural 

Source
pub enum Natural {
    Zero,
    Nonzero(Composite),
}
Expand description

Natural number, either a Composite or Zero

m = prod p_k^{n_k} OR 0

Note this struct does NOT implement Divisible. That trait is meant for numbers that can be uniquely decomposed into Primes. This is not the case, since Natural can be zero.

Variants§

§

Zero

The natural number 0

§

Nonzero(Composite)

A nonzero natural number

Implementations§

Source§

impl Natural

Source

pub fn gcd(&self, other: &Self) -> Self

Greatest common divisor

use adic::divisible::Natural;
let n1 = Natural::from(6);
let n2 = Natural::from(15);
assert_eq!(Natural::from(3), n1.gcd(&n2));
§Panics

Panics if either self or other are zero

Source

pub fn lcm(&self, other: &Self) -> Self

Least common multiple

use adic::divisible::Natural;
let n1 = Natural::from(6);
let n2 = Natural::from(15);
assert_eq!(Natural::from(30), n1.lcm(&n2));
assert_eq!(Natural::from(0), n1.lcm(&Natural::from(0)));

Trait Implementations§

Source§

impl Add<&Natural> for Natural

Source§

type Output = Natural

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Natural) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Natural> for &Natural

Source§

type Output = Natural

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Natural) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for &Natural

Source§

type Output = Natural

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Natural

Source§

type Output = Natural

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Natural) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Natural

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Natural

Source§

fn clone(&self) -> Natural

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Natural

Source§

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

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

impl Display for Natural

Source§

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

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

impl From<BigUint> for Natural

Source§

fn from(u: BigUint) -> Self

Converts to this type from the input type.
Source§

impl From<Composite> for Natural

Source§

fn from(value: Composite) -> Self

Converts to this type from the input type.
Source§

impl From<Natural> for BigUint

Source§

fn from(n: Natural) -> Self

Converts to this type from the input type.
Source§

impl From<Natural> for u32

Source§

fn from(n: Natural) -> Self

Converts to this type from the input type.
Source§

impl From<Prime> for Natural

Source§

fn from(value: Prime) -> Self

Converts to this type from the input type.
Source§

impl From<PrimePower> for Natural

Source§

fn from(value: PrimePower) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Natural

Source§

fn from(u: u32) -> Self

Converts to this type from the input type.
Source§

impl Mul<&Natural> for Natural

Source§

type Output = Natural

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Natural) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Natural> for &Natural

Source§

type Output = Natural

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Natural) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for &Natural

Source§

type Output = Natural

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Natural

Source§

type Output = Natural

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Natural) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for Natural

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl One for Natural

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

impl PartialEq for Natural

Source§

fn eq(&self, other: &Natural) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Pow<u32> for Natural

Source§

type Output = Natural

The result after applying the operator.
Source§

fn pow(self, power: u32) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Product for Natural

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Rem<Composite> for Natural

Source§

type Output = BigUint

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Composite) -> Self::Output

Performs the % operation. Read more
Source§

impl Sum for Natural

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Zero for Natural

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl Eq for Natural

Source§

impl StructuralPartialEq for Natural

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LocalOne for T
where T: One + PartialEq,

Source§

fn local_one(&self) -> T

Returns a one local to self
Source§

fn is_local_one(&self) -> bool

Checks whether or not self is equivalent to its local one
Source§

fn set_local_one(&mut self)

Sets the object equal to its local one
Source§

impl<T> LocalZero for T
where T: Zero,

Source§

fn local_zero(&self) -> T

Returns a zero local to self
Source§

fn is_local_zero(&self) -> bool

Checks whether or not self is equivalent to its local zero
Source§

fn set_local_zero(&mut self)

Sets the object equal to its local zero
Source§

impl<A, N> PrimedInto<A> for N
where A: PrimedFrom<N>,

Source§

fn primed_into<P>(self, p: P) -> A
where P: Into<Prime>,

Convert from Self to A with Prime p Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<A, N> TryPrimedInto<A> for N
where A: TryPrimedFrom<N>,

Source§

type Error = <A as TryPrimedFrom<N>>::Error

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

fn try_primed_into<P>(self, p: P) -> Result<A, <N as TryPrimedInto<A>>::Error>
where P: Into<Prime>,

Convert from Self to A with Prime p Read more