Skip to content

Commit

Permalink
Added Neg operator for i*. (#3624)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Aug 1, 2023
1 parent ad7f867 commit 8dab96e
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 @@ -1929,6 +1929,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 @@ -2021,6 +2028,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 @@ -2113,6 +2127,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 @@ -2205,6 +2226,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 @@ -2297,6 +2325,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 8dab96e

Please sign in to comment.