[][src]Struct iota_ternary_preview::bigint::u384::U384

pub struct U384<E, T> { /* fields omitted */ }

Methods

impl<E, T> U384<E, T>[src]

pub fn inner_ref(&self) -> &T[src]

impl U384<BigEndian, U32Repr>[src]

pub fn as_i384(self) -> I384<BigEndian, U32Repr>[src]

pub fn shift_into_i384(self) -> I384<BigEndian, U32Repr>[src]

pub fn add_inplace(&mut self, other: Self)[src]

Adds other onto self in place.

pub fn add_digit_inplace<T: Into<u32>>(&mut self, other: T) -> usize[src]

Adds other in place, returning the number of digits required accomodate other (starting from the least significant one).

pub fn divide_by_two(&mut self)[src]

Divides the u384 by 2 by bitshifting all bits one position to the right.

pub fn from_t242(trits: T242<Utrit>) -> Self[src]

pub fn sub_inplace(&mut self, other: Self)[src]

Subtract other from self inplace.

This function is defined in terms of overflowing_add by making use of the following identity (in terms of Two's complement, and where ! is logical bitwise negation):

!x = -x - 1 => -x = !x + 1

pub fn try_from_t243(trits: T243<Utrit>) -> Result<Self, Error>[src]

Converts a signed integer represented by the balanced trits in t243 to the unsigned binary integer u384. It does this by shifting the t243 into signed range (by adding 1 to all its trits). t243 is assumed to be in little endian representation, with the most significant trit being at the largest index in the array.

This is done in the following steps:

  1. 1 is added to all balanced trits, making them unsigned: {-1, 0, 1} -> {0, 1, 2}.
  2. The t243 are converted to base 10 and through this immediately to i384 by calculating the sum `s
This example is not tested
s = t_242 * 3^241 + t_241 * 3^240 + ...
  + t_{i+1} * 3^{i} + t_i * 3^{i-1} + t_{i-1} * 3^{i-2} + ...
  + t_1 * 3 + t_0

To perform this sum efficiently, its accumulation is staggered, so that each multiplication by 3 is done in each iteration of accumulating loop. This can be understood by factoring the powers of 3 from the previous sum:

This example is not tested
s = (...((t_242 * 3 + t_241) * 3 + t_240) * 3 + ...
  +  ...((t_{i+1} * 3 + t_i) * 3 + t_{i-1}) * 3 + ...
  +  ...t_1) * 3 + t_0

Expressed in procedural form, this is the sum accumulated in acc with the index i running from [242..0]:

This example is not tested
acc = 0
for i, trit in trits.rev():
    acc := acc + trit * 3^i

impl U384<LittleEndian, U32Repr>[src]

pub fn as_i384(self) -> I384<LittleEndian, U32Repr>[src]

pub fn add_inplace(&mut self, other: Self)[src]

Adds other onto self in place.

pub fn add_digit_inplace<T: Into<u32>>(&mut self, other: T) -> usize[src]

Adds other in place, returning the number of digits required accomodate other (starting from the least significant one).

pub fn divide_by_two(&mut self)[src]

Divides the u384 by 2 by bitshifting all bits one position to the right.

pub fn from_t242(trits: T242<Utrit>) -> Self[src]

pub fn shift_into_i384(self) -> I384<LittleEndian, U32Repr>[src]

pub fn sub_inplace(&mut self, other: Self)[src]

Subtract other from self inplace.

This function is defined in terms of overflowing_add by making use of the following identity (in terms of Two's complement, and where ! is logical bitwise negation):

!x = -x -1 => -x = !x + 1

pub fn try_from_t243(trits: T243<Utrit>) -> Result<Self, Error>[src]

Converts a signed integer represented by the balanced trits in t243 to the unsigned binary integer u384. It does this by shifting the t243 into signed range (by adding 1 to all its trits). t243 is assumed to be in little endian representation, with the most significant trit being at the largest index in the array.

This is done in the following steps:

  1. 1 is added to all balanced trits, making them unsigned: {-1, 0, 1} -> {0, 1, 2}.
  2. The t243 are converted to base 10 and through this immediately to i384 by calculating the sum `s
This example is not tested
s = t_242 * 3^241 + t_241 * 3^240 + ...
  + t_{i+1} * 3^{i} + t_i * 3^{i-1} + t_{i-1} * 3^{i-2} + ...
  + t_1 * 3 + t_0

To perform this sum efficiently, its accumulation is staggered, so that each multiplication by 3 is done in each iteration of accumulating loop. This can be understood by factoring the powers of 3 from the previous sum:

This example is not tested
s = (...((t_242 * 3 + t_241) * 3 + t_240) * 3 + ...
  +  ...((t_{i+1} * 3 + t_i) * 3 + t_{i-1}) * 3 + ...
  +  ...t_1) * 3 + t_0

Expressed in procedural form, this is the sum accumulated in acc with the index i running from [242..0]:

This example is not tested
acc = 0
for i, trit in trits.rev():
    acc := acc + trit * 3^i

impl U384<BigEndian, U8Repr>[src]

pub const fn from_array(inner: U8Repr) -> Self[src]

impl U384<BigEndian, U32Repr>[src]

pub const fn from_array(inner: U32Repr) -> Self[src]

impl U384<LittleEndian, U8Repr>[src]

pub const fn from_array(inner: U8Repr) -> Self[src]

impl U384<LittleEndian, U32Repr>[src]

pub const fn from_array(inner: U32Repr) -> Self[src]

impl U384<BigEndian, U8Repr>[src]

pub const fn zero() -> Self[src]

pub const fn one() -> Self[src]

pub const fn two() -> Self[src]

pub const fn max() -> Self[src]

impl U384<LittleEndian, U8Repr>[src]

pub const fn zero() -> Self[src]

pub const fn one() -> Self[src]

pub const fn two() -> Self[src]

pub const fn max() -> Self[src]

impl U384<BigEndian, U32Repr>[src]

pub const fn zero() -> Self[src]

pub const fn one() -> Self[src]

pub const fn two() -> Self[src]

pub const fn max() -> Self[src]

impl U384<LittleEndian, U32Repr>[src]

pub const fn zero() -> Self[src]

pub const fn one() -> Self[src]

pub const fn two() -> Self[src]

pub const fn max() -> Self[src]

Trait Implementations

impl<E: Clone, T: Clone> Clone for U384<E, T>[src]

impl<E: Copy, T: Copy> Copy for U384<E, T>[src]

impl<E: Debug, R: BinaryRepresentation, D> Debug for U384<E, R> where
    E: Debug,
    R: BinaryRepresentation<T = D>,
    D: Debug
[src]

impl Eq for U384<LittleEndian, U32Repr>[src]

impl From<T242<Utrit>> for U384<LittleEndian, U32Repr>[src]

impl From<U384<BigEndian, [u32; 12]>> for T243<Utrit>[src]

impl From<U384<BigEndian, [u32; 12]>> for U384<BigEndian, U8Repr>[src]

impl From<U384<BigEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>[src]

impl From<U384<BigEndian, [u8; 48]>> for U384<LittleEndian, U8Repr>[src]

impl From<U384<LittleEndian, [u32; 12]>> for T242<Utrit>[src]

impl From<U384<LittleEndian, [u32; 12]>> for T243<Utrit>[src]

impl From<U384<LittleEndian, [u32; 12]>> for U384<BigEndian, U32Repr>[src]

impl From<U384<LittleEndian, [u8; 48]>> for U384<LittleEndian, U32Repr>[src]

impl From<U384<LittleEndian, [u8; 48]>> for U384<BigEndian, U8Repr>[src]

impl Ord for U384<LittleEndian, U32Repr>[src]

impl PartialEq<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>[src]

impl PartialOrd<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>[src]

impl TryFrom<T243<Utrit>> for U384<LittleEndian, U32Repr>[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<E, T> RefUnwindSafe for U384<E, T> where
    E: RefUnwindSafe,
    T: RefUnwindSafe

impl<E, T> Send for U384<E, T> where
    E: Send,
    T: Send

impl<E, T> Sync for U384<E, T> where
    E: Sync,
    T: Sync

impl<E, T> Unpin for U384<E, T> where
    E: Unpin,
    T: Unpin

impl<E, T> UnwindSafe for U384<E, T> where
    E: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,