mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
Fix big subtraction for very large numbers on edges of overflow.
This commit is contained in:
+4
-1
@@ -499,7 +499,7 @@ void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) {
|
|||||||
smaller = &neg_abs;
|
smaller = &neg_abs;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GB_PANIC("Invalid bit_int_cmp value");
|
GB_PANIC("Invalid big_int_cmp value");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,6 +530,9 @@ void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) {
|
|||||||
if (sub_overflow_u64(v, prev_overflow, &v)) {
|
if (sub_overflow_u64(v, prev_overflow, &v)) {
|
||||||
found_word = true;
|
found_word = true;
|
||||||
overflow += 1;
|
overflow += 1;
|
||||||
|
} else {
|
||||||
|
// IMPORTANT TODO(bill): Is this mathematics correct here?
|
||||||
|
v += prev_overflow;
|
||||||
}
|
}
|
||||||
dst->d.words[i] = v;
|
dst->d.words[i] = v;
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user