mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[poincare] Handle allocation failures in NaturalIntegerAbstract::udiv
This commit is contained in:
@@ -22,10 +22,10 @@ Integer Arithmetic::GCD(const Integer a, const Integer b) {
|
||||
i.setNegative(false);
|
||||
j.setNegative(false);
|
||||
do {
|
||||
if (i.isZero()) {
|
||||
if (j.isAllocationFailure() || i.isZero()) {
|
||||
return j;
|
||||
}
|
||||
if (j.isZero()) {
|
||||
if (i.isAllocationFailure() || j.isZero()) {
|
||||
return i;
|
||||
}
|
||||
if (Integer::NaturalOrder(i, j) > 0) {
|
||||
|
||||
@@ -280,6 +280,13 @@ IntegerDivision NaturalIntegerAbstract::udiv(const NaturalIntegerAbstract * nume
|
||||
|
||||
Integer A(numerator);
|
||||
Integer B(denominator);
|
||||
if (A.isAllocationFailure()) {
|
||||
return {.quotient = A, .remainder = A};
|
||||
}
|
||||
if (B.isAllocationFailure()) {
|
||||
return {.quotient = B, .remainder = B};
|
||||
}
|
||||
|
||||
native_int_t base = 1 << 16;
|
||||
// TODO: optimize by just swifting digit and finding 2^kB that makes B normalized
|
||||
native_int_t d = base/(native_int_t)(B.node()->halfDigit(B.node()->numberOfHalfDigits()-1)+1);
|
||||
|
||||
Reference in New Issue
Block a user