mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Fix big_int_or and big_int_xor
This commit is contained in:
+17
-15
@@ -1248,15 +1248,15 @@ void big_int_xor(BigInt *dst, BigInt const *x, BigInt const *y) {
|
|||||||
x = y;
|
x = y;
|
||||||
y = tmp;
|
y = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// x ^ (-y) == x ^ ~(y-1) == ~(x ^ (y-1)) == -((x ^ (y-1)) + 1)
|
|
||||||
|
|
||||||
dst->neg = false;
|
dst->neg = false;
|
||||||
BigInt y1 = big_int_make_abs(y);
|
if (y->neg) {
|
||||||
big_int_sub_eq(&y1, &BIG_INT_ONE);
|
// x ^ (-y) == x ^ ~(y-1) == ~(x ^ (y-1)) == -((x ^ (y-1)) + 1)
|
||||||
big_int__xor_abs(dst, x, &y1);
|
BigInt y1 = big_int_make_abs(y);
|
||||||
big_int_add_eq(dst, &BIG_INT_ONE);
|
big_int_sub_eq(&y1, &BIG_INT_ONE);
|
||||||
dst->neg = true;
|
big_int__xor_abs(dst, x, &y1);
|
||||||
|
big_int_add_eq(dst, &BIG_INT_ONE);
|
||||||
|
dst->neg = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1316,13 +1316,15 @@ void big_int_or(BigInt *dst, BigInt const *x, BigInt const *y) {
|
|||||||
x = y;
|
x = y;
|
||||||
y = tmp;
|
y = tmp;
|
||||||
}
|
}
|
||||||
|
dst->neg = false;
|
||||||
// x | (-y) == x | ~(y-1) == ~((y-1) &~ x) == -(~((y-1) &~ x) + 1)
|
if (y->neg) {
|
||||||
BigInt y1 = big_int_make_abs(y);
|
// x | (-y) == x | ~(y-1) == ~((y-1) &~ x) == -(~((y-1) &~ x) + 1)
|
||||||
big_int_sub_eq(&y1, &BIG_INT_ONE);
|
BigInt y1 = big_int_make_abs(y);
|
||||||
big_int__and_not_abs(dst, &y1, x);
|
big_int_sub_eq(&y1, &BIG_INT_ONE);
|
||||||
big_int_add_eq(dst, &BIG_INT_ONE);
|
big_int__and_not_abs(dst, &y1, x);
|
||||||
dst->neg = true;
|
big_int_add_eq(dst, &BIG_INT_ONE);
|
||||||
|
dst->neg = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user