diff --git a/packages/math/src/i257.cairo b/packages/math/src/i257.cairo index 694f2cac..325c5796 100644 --- a/packages/math/src/i257.cairo +++ b/packages/math/src/i257.cairo @@ -1,3 +1,4 @@ +use core::fmt::{Display, Formatter, Error}; use core::num::traits::Zero; use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign}; @@ -353,3 +354,14 @@ impl FeltIntoI257 of Into { i257 { abs: self.into(), is_negative: false } } } + +// Implements the Display trait for i257. +pub impl DisplayI257Impl of Display { + fn fmt(self: @i257, ref f: Formatter) -> Result<(), Error> { + if *self.is_negative { + write!(f, "-")?; + } + self.abs.fmt(ref f) + } +} +