Skip to content

Commit

Permalink
Add fmt::Display to fields. (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware authored Jan 7, 2025
1 parent f5f4112 commit 1d3c822
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ impl CM31PartialOrd of PartialOrd<CM31> {
}
}

impl DisplayCM31 of core::fmt::Display<CM31> {
fn fmt(self: @CM31, ref f: core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "{} + {}i", self.a, self.b)
}
}

#[inline]
pub fn cm31(a: u32, b: u32) -> CM31 {
CM31 { a: m31(a), b: m31(b) }
Expand Down
6 changes: 6 additions & 0 deletions stwo_cairo_verifier/crates/verifier_core/src/fields/m31.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ pub impl M31SubConstrain0 of bounded_int::ConstrainHelper<BoundedInt<{ -(P - 1)
type HighT = M31InnerT;
}

impl DisplayM31 of core::fmt::Display<M31> {
fn fmt(self: @M31, ref f: core::fmt::Formatter) -> Result<(), core::fmt::Error> {
self.inner.fmt(ref f)
}
}

#[cfg(test)]
mod tests {
use super::super::Invertible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ pub impl CM31IntoPackedUnreducedCM31 of Into<CM31, PackedUnreducedCM31> {
}
}

impl DisplayQM31 of core::fmt::Display<QM31> {
fn fmt(self: @QM31, ref f: core::fmt::Formatter) -> Result<(), core::fmt::Error> {
write!(f, "({}) + ({})u", self.a, self.b)
}
}

#[cfg(test)]
mod tests {
use super::super::Invertible;
Expand Down

0 comments on commit 1d3c822

Please sign in to comment.