subtract method
Implementation
LexoInteger subtract(LexoInteger other) {
checkSystem(other);
if (isZero()) {
return other.negate();
}
if (other.isZero()) {
return this;
}
if (!identical(sign, other.sign)) {
var negate;
if (identical(sign, -1)) {
negate = this.negate();
final sum = negate.add(other);
return sum.negate();
}
negate = other.negate();
return add(negate);
}
final cmp = LexoInteger.compare(mag, other.mag);
if (identical(cmp, 0)) {
return LexoInteger.zero(sys);
}
return cmp < 0
? LexoInteger.make(sys, identical(sign, -1) ? 1 : -1,
LexoInteger.Subtract(sys, other.mag, mag))
: LexoInteger.make(sys, identical(sign, -1) ? -1 : 1,
LexoInteger.Subtract(sys, mag, other.mag));
}