mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 01:08:15 +01:00
[poincare/arithmetic] Shortcut the LCM and GCD computation if equal
This fixes: LCM(7.88861e+169, 7.88861e+169), which overflowed at some point during the computation
This commit is contained in:
committed by
RubenNumworks
parent
97d94d9e56
commit
313cbf6767
@@ -7,6 +7,9 @@ Integer Arithmetic::LCM(const Integer & a, const Integer & b) {
|
||||
if (a.isZero() || b.isZero()) {
|
||||
return Integer(0);
|
||||
}
|
||||
if (a.isEqualTo(b)) {
|
||||
return a;
|
||||
}
|
||||
Integer signResult = Integer::Division(Integer::Multiplication(a, b), GCD(a, b)).quotient;
|
||||
signResult.setNegative(false);
|
||||
return signResult;
|
||||
@@ -16,7 +19,9 @@ Integer Arithmetic::GCD(const Integer & a, const Integer & b) {
|
||||
if (a.isOverflow() || b.isOverflow()) {
|
||||
return Integer::Overflow(false);
|
||||
}
|
||||
|
||||
if (a.isEqualTo(b)) {
|
||||
return a;
|
||||
}
|
||||
Integer i = a;
|
||||
Integer j = b;
|
||||
i.setNegative(false);
|
||||
|
||||
Reference in New Issue
Block a user