Skip to content

Commit

Permalink
i257 remove pub on struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Apr 9, 2024
1 parent 56da76a commit 8a8d5a5
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 153 deletions.
25 changes: 23 additions & 2 deletions src/math/src/i257.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use core::num::traits::Zero;
// The is_negative field is true for negative integers, and false for non-negative integers.
#[derive(Serde, Copy, Drop, Hash)]
pub struct i257 {
pub abs: u256,
pub is_negative: bool,
abs: u256,
is_negative: bool,
}

#[inline(always)]
// TODO Later this should prob be updated to a trait
// To be used like I257Trait::new()
pub fn i257_new(abs: u256, is_negative: bool) -> i257 {
if abs == 0 {
i257 { abs, is_negative: false }
Expand All @@ -19,6 +21,25 @@ pub fn i257_new(abs: u256, is_negative: bool) -> i257 {
}
}

#[generate_trait]
pub impl I257Impl of I257Trait {
fn new(abs: u256, is_negative: bool) -> i257 {
if abs == 0 {
i257 { abs, is_negative: false }
} else {
i257 { abs, is_negative }
}
}

fn is_negative(self: i257) -> bool {
self.is_negative
}

fn abs(self: i257) -> u256 {
self.abs
}
}

impl I128Default of Default<i257> {
fn default() -> i257 {
Zero::zero()
Expand Down
Loading

0 comments on commit 8a8d5a5

Please sign in to comment.