Skip to content

Commit

Permalink
Field debug implementations (#501)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/stwo/501)
<!-- Reviewable:end -->
  • Loading branch information
spapinistarkware authored Mar 19, 2024
1 parent 4d3c04d commit 828bdf3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/core/fields/cm31.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::fmt::{Debug, Display};
use std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
};
Expand All @@ -12,7 +12,7 @@ pub const P2: u64 = 4611686014132420609; // (2 ** 31 - 1) ** 2
/// Complex extension field of M31.
/// Equivalent to M31\[x\] over (x^2 + 1) as the irreducible polynomial.
/// Represented as (a, b) of a + bi.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CM31(pub M31, pub M31);

impl_field!(CM31, P2);
Expand All @@ -34,6 +34,12 @@ impl Display for CM31 {
}
}

impl Debug for CM31 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} + {}i", self.0, self.1)
}
}

impl Mul for CM31 {
type Output = Self;

Expand Down
10 changes: 8 additions & 2 deletions src/core/fields/qm31.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::fmt::{Debug, Display};
use std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
};
Expand All @@ -15,7 +15,7 @@ pub const R: CM31 = CM31::from_u32_unchecked(2, 1);
/// Extension field of CM31.
/// Equivalent to CM31\[x\] over (x^2 - 2 - i) as the irreducible polynomial.
/// Represented as ((a, b), (c, d)) of (a + bi) + (c + di)u.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct QM31(pub CM31, pub CM31);
pub type SecureField = QM31;

Expand Down Expand Up @@ -49,6 +49,12 @@ impl Display for QM31 {
}
}

impl Debug for QM31 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}) + ({})u", self.0, self.1)
}
}

impl Mul for QM31 {
type Output = Self;

Expand Down

0 comments on commit 828bdf3

Please sign in to comment.