Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Neg operator for i*. #3624

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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