Skip to content

Commit

Permalink
Added Neg operator for i*.
Browse files Browse the repository at this point in the history
commit-id:e1d9fd58
  • Loading branch information
orizi committed Jul 26, 2023
1 parent f1744f0 commit cbef09f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions corelib/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,13 @@ impl I8SubEq of SubEq<i8> {
}
}

impl I8Neg of Neg<i8> {
#[inline(always)]
fn neg(a: i8) -> i8 {
0 - a
}
}

extern fn i8_wide_mul(lhs: i8, rhs: i8) -> i16 implicits() nopanic;
impl I8Mul of Mul<i8> {
fn mul(lhs: i8, rhs: i8) -> i8 {
Expand Down Expand Up @@ -2147,6 +2154,13 @@ impl I16SubEq of SubEq<i16> {
}
}

impl I16Neg of Neg<i16> {
#[inline(always)]
fn neg(a: i16) -> i16 {
0 - a
}
}

extern fn i16_wide_mul(lhs: i16, rhs: i16) -> i32 implicits() nopanic;
impl I16Mul of Mul<i16> {
fn mul(lhs: i16, rhs: i16) -> i16 {
Expand Down Expand Up @@ -2239,6 +2253,13 @@ impl I32SubEq of SubEq<i32> {
}
}

impl I32Neg of Neg<i32> {
#[inline(always)]
fn neg(a: i32) -> i32 {
0 - a
}
}

extern fn i32_wide_mul(lhs: i32, rhs: i32) -> i64 implicits() nopanic;
impl I32Mul of Mul<i32> {
fn mul(lhs: i32, rhs: i32) -> i32 {
Expand Down Expand Up @@ -2331,6 +2352,13 @@ impl I64SubEq of SubEq<i64> {
}
}

impl I64Neg of Neg<i64> {
#[inline(always)]
fn neg(a: i64) -> i64 {
0 - a
}
}

extern fn i64_wide_mul(lhs: i64, rhs: i64) -> i128 implicits() nopanic;
impl I64Mul of Mul<i64> {
fn mul(lhs: i64, rhs: i64) -> i64 {
Expand Down Expand Up @@ -2423,6 +2451,12 @@ impl I128SubEq of SubEq<i128> {
}
}

impl I128Neg of Neg<i128> {
#[inline(always)]
fn neg(a: i128) -> i128 {
0 - a
}
}

/// If `lhs` >= `rhs` returns `Ok(lhs - rhs)` else returns `Err(2**128 + lhs - rhs)`.
extern fn i128_diff(lhs: i128, rhs: i128) -> Result<u128, u128> implicits(RangeCheck) nopanic;
Expand Down

0 comments on commit cbef09f

Please sign in to comment.