Skip to content

Commit

Permalink
Extract local variable
Browse files Browse the repository at this point in the history
  • Loading branch information
skrzypo987 committed Sep 9, 2020
1 parent c7cb2f0 commit 53ce46e
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,22 @@ public static Slice subtract(Slice left, Slice right)

public static void subtract(Slice left, Slice right, Slice result)
{
if (isNegative(left) != isNegative(right)) {
boolean leftNegative = isNegative(left);
boolean rightNegative = isNegative(right);

if (leftNegative != rightNegative) {
// only one is negative
if (addUnsignedReturnOverflow(left, right, result, isNegative(left)) != 0) {
if (addUnsignedReturnOverflow(left, right, result, leftNegative) != 0) {
throwOverflowException();
}
}
else {
int compare = compareAbsolute(left, right);
if (compare > 0) {
subtractUnsigned(left, right, result, isNegative(left) && isNegative(right));
subtractUnsigned(left, right, result, leftNegative);
}
else if (compare < 0) {
subtractUnsigned(right, left, result, !(isNegative(left) && isNegative(right)));
subtractUnsigned(right, left, result, !leftNegative);
}
else {
setToZero(result);
Expand Down

0 comments on commit 53ce46e

Please sign in to comment.