Skip to content

Commit

Permalink
Merge pull request #9 from icanvardar/feat/#3-arithmetic
Browse files Browse the repository at this point in the history
Format `SignedInt` Operation Functions
  • Loading branch information
icanvardar authored Jul 28, 2024
2 parents 4ac8e04 + 08c09c9 commit c8dfd57
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/types/SignedInt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ function divSignedInt(SignedInt left, SignedInt right) pure returns (SignedInt r
revert(0x9c, 0x04)
}

let leftNeg := slt(left, 0)
let rightNeg := slt(right, 0)
let sign := xor(leftNeg, rightNeg)
let l := slt(left, 0)
let r := slt(right, 0)
let sign := xor(l, r)

if leftNeg { left := sub(0, left) }
if rightNeg { right := sub(0, right) }
if l { left := sub(0, left) }
if r { right := sub(0, right) }

let absRes := div(left, right)
res := absRes
if sign { res := sub(0, absRes) }
res := div(left, right)

if sign { res := sub(0, res) }
}
}

Expand All @@ -63,13 +63,13 @@ function modSignedInt(SignedInt left, SignedInt right) pure returns (SignedInt r
revert(0x9c, 0x04)
}

let leftNeg := slt(left, 0)
if leftNeg { left := sub(0, left) }
let l := slt(left, 0)
if l { left := sub(0, left) }
if slt(right, 0) { right := sub(0, right) }

let absRes := mod(left, right)
res := absRes
if leftNeg { res := sub(0, absRes) }
res := mod(left, right)

if l { res := sub(0, res) }
}
}

Expand All @@ -81,12 +81,9 @@ function expSignedInt(SignedInt left, SignedInt right) pure returns (SignedInt r
revert(0x9c, 0x04)
}

let leftNeg := slt(left, 0)
let absLeft := left

res := exp(absLeft, right)
res := exp(left, right)

if leftNeg { res := sub(0, res) }
if slt(left, 0) { res := sub(0, res) }
}
}

Expand Down

0 comments on commit c8dfd57

Please sign in to comment.