Skip to content

Commit

Permalink
feat: implement Display trait for i257 (#327)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

## Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: N/A

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Implemented Display trait for `i257`

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->
  • Loading branch information
JhChoy authored Aug 30, 2024
1 parent fdf4098 commit 8208871
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/math/src/i257.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt::{Display, Formatter, Error};
use core::num::traits::Zero;
use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};

Expand Down Expand Up @@ -353,3 +354,14 @@ impl FeltIntoI257 of Into<felt252, i257> {
i257 { abs: self.into(), is_negative: false }
}
}

// Implements the Display trait for i257.
pub impl DisplayI257Impl of Display<i257> {
fn fmt(self: @i257, ref f: Formatter) -> Result<(), Error> {
if *self.is_negative {
write!(f, "-")?;
}
self.abs.fmt(ref f)
}
}

0 comments on commit 8208871

Please sign in to comment.