Struct g2poly::G2PolyProd

source ·
pub struct G2PolyProd(pub u128);
Expand description

The result of multiplying two G2Poly

This type is used to represent the result of multiplying two G2Polys. Since this could overflow when relying on just a u64, this type uses an internal u128. The only operation implemented on this type is % which reduces the result back to a G2Poly.

let a = G2Poly(0xff_00_00_00_00_00_00_00);
assert_eq!(a * a, G2PolyProd(0x55_55_00_00_00_00_00_00_00_00_00_00_00_00_00_00));
assert_eq!(a * a % G2Poly(0b100), G2Poly(0));

Tuple Fields§

§0: u128

Implementations§

Convert to G2Poly

Panics

Panics, if the internal representation exceeds the maximum value for G2Poly.

Example

let a = G2Poly(0x40_00_00_00_00_00_00_00) * G2Poly(2);
assert_eq!(G2Poly(0x80_00_00_00_00_00_00_00), a.to_poly());

// Next line would panics!
// (G2Poly(0x40_00_00_00_00_00_00_00) * G2Poly(4)).to_poly();

Convert to G2Poly if possible

In case the value would not fit into G2Poly, return None

Example
assert_eq!((G2Poly(0x40_00_00_00_00_00_00_00) * G2Poly(2)).try_to_poly(), Some(G2Poly(0x80_00_00_00_00_00_00_00)));
assert_eq!((G2Poly(0x40_00_00_00_00_00_00_00) * G2Poly(4)).try_to_poly(), None);

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Calculate the polynomial remainder of the product of polynomials

When calculating a % b this computes the value of r in a = q * b + r such that |r| < |b|.

Example
let a = G2Poly(0x12_34_56_78_9A_BC_DE);
let m = G2Poly(0x00_00_00_01_00_00);
assert!((a * a % m).degree().expect("Positive degree") < m.degree().expect("Positive degree"));
assert_eq!(G2Poly(0b0101_0001_0101_0100), a * a % m);
The resulting type after applying the % operator.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.