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 G2Poly
s. 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§
source§impl G2PolyProd
impl G2PolyProd
sourcepub fn to_poly(self) -> G2Poly
pub fn to_poly(self) -> G2Poly
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();
sourcepub fn try_to_poly(self) -> Option<G2Poly>
pub fn try_to_poly(self) -> Option<G2Poly>
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§
source§impl Clone for G2PolyProd
impl Clone for G2PolyProd
source§fn clone(&self) -> G2PolyProd
fn clone(&self) -> G2PolyProd
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for G2PolyProd
impl Debug for G2PolyProd
source§impl Ord for G2PolyProd
impl Ord for G2PolyProd
source§fn cmp(&self, other: &G2PolyProd) -> Ordering
fn cmp(&self, other: &G2PolyProd) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<G2PolyProd> for G2PolyProd
impl PartialEq<G2PolyProd> for G2PolyProd
source§fn eq(&self, other: &G2PolyProd) -> bool
fn eq(&self, other: &G2PolyProd) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<G2PolyProd> for G2PolyProd
impl PartialOrd<G2PolyProd> for G2PolyProd
source§fn partial_cmp(&self, other: &G2PolyProd) -> Option<Ordering>
fn partial_cmp(&self, other: &G2PolyProd) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Rem<G2Poly> for G2PolyProd
impl Rem<G2Poly> for G2PolyProd
source§fn rem(self, rhs: G2Poly) -> G2Poly
fn rem(self, rhs: G2Poly) -> G2Poly
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);