Fixed a bug with negative numbers and replaced the algebra screenshot

This commit is contained in:
Andrea Cavalli 2017-07-24 23:36:43 +02:00
parent fef549b651
commit 70adfc81b6
3 changed files with 23 additions and 6 deletions

View File

@ -202,11 +202,26 @@ public class Number implements Function {
public LinkedList<BigInteger> getFactors() {
BigInteger n = getTerm().toBigIntegerExact();
final BigInteger two = BigInteger.valueOf(2);
final BigInteger zero = BigInteger.ZERO;
final LinkedList<BigInteger> fs = new LinkedList<>();
if (n.compareTo(two) < 0) {
throw new IllegalArgumentException("must be greater than one");
final int comparedToZero = n.compareTo(zero);
final int comparedToTwo = n.compareTo(two);
if (comparedToZero == 0) {
return fs;
}
if (comparedToTwo < 0) {
if (comparedToZero > 0) {
return fs;
} else {
fs.add(BigInteger.valueOf(-1));
n = n.multiply(BigInteger.valueOf(-1));
}
}
if (n.compareTo(two) < 0) {
throw new IllegalArgumentException("must be greater than one");
}
while (n.mod(two).equals(BigInteger.ZERO)) {
fs.add(two);

View File

@ -37,10 +37,12 @@ public class FeatureNumber implements FeatureBasic {
nmbstr = '0' + nmbstr;
} else if (nmbstr.charAt(nmbstr.length() - 1) == '.') {
nmbstr += "0";
} else if (nmbstr.charAt(0) == MathematicalSymbols.MINUS) {
nmbstr += "1";
} else if (nmbstr.charAt(0) == MathematicalSymbols.SUBTRACTION) {
nmbstr += "1";
} else if (nmbstr.length() == 1) {
if (nmbstr.charAt(0) == MathematicalSymbols.MINUS) {
nmbstr += "1";
} else if (nmbstr.charAt(0) == MathematicalSymbols.SUBTRACTION) {
nmbstr += "1";
}
}
return new Number(context, nmbstr);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB