Added a draft of a decimal/non-exact mode

This commit is contained in:
XDrake99 2016-12-05 19:58:49 +01:00
parent 29bbe47439
commit 7417fcefe7
41 changed files with 260 additions and 173 deletions

Binary file not shown.

Binary file not shown.

View File

@ -18,7 +18,6 @@ import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.device.graphicengine.RAWFont;
import org.warp.picalculator.math.functions.AnteriorFunction;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.EmptyNumber;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
@ -37,7 +36,7 @@ import com.rits.cloning.Cloner;
public class Utils {
public static final int scale = 24;
public static final int resultScale = 8*5;
public static final int displayScale = 8;
public static final int scaleMode = BigDecimal.ROUND_HALF_UP;
public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP;
@ -469,8 +468,8 @@ public class Utils {
public static boolean isNegative(Function b) {
if (b instanceof Negative) {
return true;
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
return true;
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
return true;
}
return false;
@ -483,4 +482,8 @@ public class Utils {
}
return result;
}
public static boolean isIntegerValue(BigDecimal bd) {
return bd.signum() == 0 || bd.scale() <= 0 || bd.stripTrailingZeros().scale() <= 0;
}
}

View File

@ -1,6 +1,17 @@
package org.warp.picalculator.device;
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
import static org.warp.picalculator.device.graphicengine.Display.Render.getMatrixOfImage;
import static org.warp.picalculator.device.graphicengine.Display.Render.glClear;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor4i;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawSkin;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringCenter;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringRight;
import static org.warp.picalculator.device.graphicengine.Display.Render.glFillRect;
import static org.warp.picalculator.device.graphicengine.Display.Render.glSetFont;
import java.awt.image.BufferedImage;
import java.io.IOException;

View File

@ -25,9 +25,8 @@ public class Calculator {
public static String angleMode = "deg";
public static Screen[] sessions = new Screen[5];
public static int currentSession = 0;
public static boolean haxMode = true;
public static boolean surdMode = true;
public static boolean haxMode = true;
public static boolean exactMode = false;
public static Function parseString(String string) throws Error {
if (string.contains("{")) {
if (!string.startsWith("{")) {

View File

@ -5,10 +5,8 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStr
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.graphicengine.Display;

View File

@ -1,17 +1,15 @@
package org.warp.picalculator.math.functions;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
import static org.warp.picalculator.device.graphicengine.Display.Render.glFillRect;
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.device.graphicengine.Display.Render;
import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.rules.FractionsRule1;
import org.warp.picalculator.math.rules.FractionsRule2;
@ -40,7 +38,10 @@ public class Division extends FunctionTwoValues {
if (FractionsRule1.compare(this)) return true;
if (FractionsRule2.compare(this)) return true;
if (FractionsRule3.compare(this)) return true;
if (UndefinedRule2.compare(this)) return true;
if (UndefinedRule2.compare(this)) return true;
if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
return true;
}
return false;
}
@ -54,7 +55,9 @@ public class Division extends FunctionTwoValues {
} else if (FractionsRule3.compare(this)) {
result = FractionsRule3.execute(this);
} else if (UndefinedRule2.compare(this)) {
result = UndefinedRule2.execute(this);
result = UndefinedRule2.execute(this);
} else if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
result.add(((Number)variable1).divide((Number)variable2).setParent(parent));
}
return result;
}

View File

@ -2,11 +2,9 @@ package org.warp.picalculator.math.functions;
import static org.warp.picalculator.Utils.ArrayToRegex;
import static org.warp.picalculator.Utils.concat;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@ -413,8 +411,8 @@ public class Expression extends FunctionMultipleValues {
Function funzione = oldFunctionsArray[i];
if (funzione != null) {
//Affinazione
if (funzione instanceof Root) {
if ((i - 1) >= 0 && oldFunctionsArray[i-1] instanceof Number && ((Number)oldFunctionsArray[i-1]).getTerm().compareTo(new BigInteger("2")) == 0) {
if (funzione instanceof Root) {
if ((i - 1) >= 0 && oldFunctionsArray[i-1] instanceof Number && ((Number)oldFunctionsArray[i-1]).getTerm().compareTo(new BigDecimal(2)) == 0) {
oldFunctionsArray[i] = null;
oldFunctionsArray[i-1] = null;
oldFunctionsList.remove(oldFunctionsList.size()-1);

View File

@ -3,8 +3,6 @@ package org.warp.picalculator.math.functions;
import java.util.Arrays;
import java.util.List;
import org.warp.picalculator.Error;
import com.rits.cloning.Cloner;
public abstract class FunctionMultipleValues implements Function {

View File

@ -3,7 +3,6 @@ package org.warp.picalculator.math.functions;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.rules.ExponentRule15;
import org.warp.picalculator.math.rules.NumberRule1;

View File

@ -3,28 +3,37 @@ package org.warp.picalculator.math.functions;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.nevec.rjm.BigDecimalMath;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.device.graphicengine.RAWFont;
import org.warp.picalculator.math.Calculator;
import com.rits.cloning.Cloner;
public class Number implements Function {
private Function parent;
protected BigInteger term;
protected BigDecimal term;
protected int width;
protected int height;
protected int line;
protected boolean small;
public Number(Function parent, BigInteger val) {
this.parent = parent;
term = val;
term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2);
}
public Number(Function parent, BigDecimal val) {
this.parent = parent;
term = val.setScale(Utils.scale, Utils.scaleMode2);
}
public Number(Function parent, String s) throws Error {
@ -32,15 +41,23 @@ public class Number implements Function {
}
public Number(Function parent, int s) {
this(parent, BigInteger.valueOf(s));
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
}
public BigInteger getTerm() {
public Number(Function parent, float s) {
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
}
public Number(Function parent, double s) {
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
}
public BigDecimal getTerm() {
return term;
}
public void setTerm(BigInteger val) {
term = val;
public void setTerm(BigDecimal val) {
term = val.setScale(Utils.scale, Utils.scaleMode2);
}
@Override
@ -66,21 +83,42 @@ public class Number implements Function {
}
public Number divide(Number f) throws Error {
Number ret = new Number(this.parent, getTerm().divide(f.getTerm()));
Number ret = new Number(this.parent, BigDecimalMath.divideRound(getTerm(), f.getTerm()));
return ret;
}
public Number pow(Number f) throws Error {
Number ret = new Number(this.parent, BigInteger.ONE);
for (BigInteger i = BigInteger.ZERO; i.compareTo(f.getTerm()) < 0; i = i.add(BigInteger.ONE)) {
ret = ret.multiply(new Number(this.parent, getTerm()));
Number ret = new Number(this.parent, BigDecimal.ONE);
if (Utils.isIntegerValue(f.term)) {
final BigInteger bi = f.term.toBigInteger();
for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) {
ret = ret.multiply(new Number(this.parent, getTerm()));
}
} else {
ret.term = BigDecimalMath.pow(term, f.term);
}
return ret;
}
@Override
public String toString() {
return getTerm().toString();
String sWith0 = getTerm().setScale(Utils.displayScale, Utils.scaleMode2).toPlainString();
String sExtendedWith0 = getTerm().toPlainString();
//Remove trailing zeroes. Thanks to Kent, http://stackoverflow.com/questions/14984664/remove-trailing-zero-in-java
String s = sWith0.indexOf(".") < 0 ? sWith0 : sWith0.replaceAll("0*$", "").replaceAll("\\.$", "");
String sExtended = sExtendedWith0.indexOf(".") < 0 ? sExtendedWith0 : sExtendedWith0.replaceAll("0*$", "").replaceAll("\\.$", "");
if (sExtended.length() > s.length()) {
s = s+"";
}
if (Calculator.exactMode == false) {
String cuttedNumber = s.split("\\.")[0];
if (cuttedNumber.length() > 8) {
return cuttedNumber.substring(0, 1)+","+cuttedNumber.substring(1, 8)+""+(cuttedNumber.length()-1);
}
}
return s;
}
// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) {
@ -104,7 +142,17 @@ public class Number implements Function {
t = t.substring(1);
}
}
glDrawStringLeft(x+1, y, t);
if (t.contains("")) {
final RAWFont defaultf = Utils.getFont(small);
final RAWFont smallf = Utils.getFont(true);
String s = t.substring(0, t.indexOf("")+2);
int sw = glGetStringWidth(defaultf, s);
glDrawStringLeft(x+1, y+smallf.charH-2, s);
Display.Render.glSetFont(smallf);
glDrawStringLeft(x+1+sw-3, y, t.substring(t.indexOf("")+2));
} else {
glDrawStringLeft(x+1, y, t);
}
}
public int getHeight(boolean drawMinus) {
@ -121,8 +169,13 @@ public class Number implements Function {
}
private int calcHeight() {
int h1 = Utils.getFontHeight(small);
return h1;
String t = toString();
if (t.contains("")) {
return Utils.getFontHeight(small)-2+Utils.getFontHeight(true);
} else {
int h1 = Utils.getFontHeight(small);
return h1;
}
}
@Override
public int getWidth() {
@ -138,7 +191,15 @@ public class Number implements Function {
t = t.substring(1);
}
}
return glGetStringWidth(Utils.getFont(small), t)+1;
if (t.contains("")) {
final RAWFont defaultf = Utils.getFont(small);
final RAWFont smallf = Utils.getFont(true);
String s = t.substring(0, t.indexOf("")+2);
int sw = glGetStringWidth(defaultf, s);
return 1+sw-3+glGetStringWidth(smallf, t.substring(t.indexOf("")+2));
} else {
return glGetStringWidth(Utils.getFont(small), t)+1;
}
}
@Override
@ -147,7 +208,12 @@ public class Number implements Function {
}
private int calcLine() {
return Utils.getFontHeight(small) / 2;
String t = toString();
if (t.contains("")) {
return (Utils.getFontHeight(small) / 2)-2+Utils.getFontHeight(true);
} else {
return Utils.getFontHeight(small) / 2;
}
}
@Override
@ -182,9 +248,9 @@ public class Number implements Function {
public boolean equals(Object o) {
if (o != null & term != null) {
if (o instanceof Number) {
BigInteger nav = ((Number) o).getTerm();
boolean na1 = term.compareTo(BigInteger.ZERO) == 0;
boolean na2 = nav.compareTo(BigInteger.ZERO) == 0;
BigDecimal nav = ((Number) o).getTerm();
boolean na1 = term.compareTo(BigDecimal.ZERO) == 0;
boolean na2 = nav.compareTo(BigDecimal.ZERO) == 0;
if (na1 == na2) {
if (na1 == true) {
return true;

View File

@ -1,10 +1,8 @@
package org.warp.picalculator.math.functions;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.rules.ExponentRule1;
import org.warp.picalculator.math.rules.ExponentRule2;

View File

@ -2,12 +2,12 @@ package org.warp.picalculator.math.functions;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.MathematicalSymbols;
public class Root extends FunctionTwoValues {
@ -41,16 +41,21 @@ public class Root extends FunctionTwoValues {
@Override
protected boolean isSolvable() {
if (variable1 instanceof Number & variable2 instanceof Number) {
if (variable1 instanceof Number & variable2 instanceof Number) {
if (Calculator.exactMode == false) {
return true;
}
try {
Number exponent = new Number(this.parent, BigInteger.ONE);
Number exponent = new Number(this.parent, BigDecimal.ONE);
exponent = exponent.divide((Number) variable1);
if (((Number)variable2).pow(exponent).pow((Number)variable1).equals(variable2)) {
Number resultVal = ((Number)variable2).pow(exponent);
Number originalVariable = resultVal.pow(new Number(null, 2));
if (originalVariable.equals(variable2)) {
return true;
}
}
} catch (Exception | Error ex) {
}
ex.printStackTrace();
}
}
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
return true;
@ -60,13 +65,20 @@ public class Root extends FunctionTwoValues {
@Override
public ArrayList<Function> solve() throws Error {
ArrayList<Function> result = new ArrayList<>();
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
result.add(new RootSquare(parent, variable2));
ArrayList<Function> result = new ArrayList<>();
if (Calculator.exactMode) {
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
result.add(new RootSquare(parent, variable2));
} else {
Number exponent = new Number(this.parent, BigInteger.ONE);
exponent = exponent.divide((Number) variable1);
result.add(((Number)variable2).pow(exponent));
}
} else {
Number exponent = new Number(this.parent, BigInteger.ONE);
exponent = exponent.divide((Number) variable1);
result.add(((Number)variable2).pow(exponent));
Number exp = (Number) variable1;
Number numb = (Number) variable2;
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
}
return result;
}

View File

@ -1,12 +1,11 @@
package org.warp.picalculator.math.functions;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.nevec.rjm.BigIntegerMath;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.MathematicalSymbols;
public class RootSquare extends AnteriorFunction {
@ -37,26 +36,37 @@ public class RootSquare extends AnteriorFunction {
@Override
protected boolean isSolvable() {
if (variable instanceof Number) {
if (BigIntegerMath.isqrt(((Number) variable).term).pow(2).compareTo(((Number) variable).term) == 0) {
if (variable instanceof Number) {
if (Calculator.exactMode == false) {
return true;
}
try {
Number exponent = new Number(this.parent, BigInteger.ONE);
exponent = exponent.divide(new Number(null, 2));
Number resultVal = ((Number)variable).pow(exponent);
Number originalVariable = resultVal.pow(new Number(null, 2));
if (originalVariable.equals(variable)) {
return true;
}
} catch (Exception | Error ex) {
}
}
return false;
}
@Override
public ArrayList<Function> solve() throws Error {
ArrayList<Function> result = new ArrayList<>();
try {
Number var = (Number) getVariable();
result.add(new Number(this.getParent(), BigIntegerMath.isqrt(var.term)));
} catch(NullPointerException ex) {
throw new Error(Errors.ERROR);
} catch(NumberFormatException ex) {
throw new Error(Errors.SYNTAX_ERROR);
} catch(ArithmeticException ex) {
throw new Error(Errors.NUMBER_TOO_SMALL);
ArrayList<Function> result = new ArrayList<>();
if (Calculator.exactMode) {
Number exponent = new Number(this.parent, BigInteger.ONE);
exponent = exponent.divide(new Number(null, 2));
result.add(((Number)variable).pow(exponent));
} else {
Number exp = new Number(null, 2);
Number numb = (Number) variable;
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
}
return result;
}

View File

@ -1,11 +1,8 @@
package org.warp.picalculator.math.functions;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.rules.ExpandRule1;
import org.warp.picalculator.math.rules.ExpandRule5;

View File

@ -2,9 +2,8 @@ package org.warp.picalculator.math.functions;
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
@ -13,7 +12,6 @@ import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.rules.NumberRule3;
import org.warp.picalculator.math.rules.NumberRule5;
import org.warp.picalculator.math.rules.NumberRule7;
import org.warp.picalculator.math.rules.SyntaxRule1;
import org.warp.picalculator.math.rules.SyntaxRule2;
import org.warp.picalculator.math.rules.VariableRule1;
import org.warp.picalculator.math.rules.VariableRule2;
@ -75,14 +73,14 @@ public class Sum extends FunctionTwoValues {
} else if (SumMethod1.compare(this)) {
result = SumMethod1.execute(this);
} else if (variable1.isSolved() & variable2.isSolved()) {
if ((parent == null || parent.getParent() == null)) {
if (((Number)variable1).term.compareTo(new BigInteger("2")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("2")) == 0) {
if ((parent == null || parent.getParent() == null)) {
if (((Number)variable1).term.compareTo(new BigDecimal(2)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(2)) == 0) {
result.add(new Joke(Joke.FISH));
return result;
} else if (((Number)variable1).term.compareTo(new BigInteger("20")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("20")) == 0) {
} else if (((Number)variable1).term.compareTo(new BigDecimal(20)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(20)) == 0) {
result.add(new Joke(Joke.TORNADO));
return result;
} else if (((Number)variable1).term.compareTo(new BigInteger("29")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("29")) == 0) {
} else if (((Number)variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(29)) == 0) {
result.add(new Joke(Joke.SHARKNADO));
return result;
}

View File

@ -4,7 +4,6 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawSt
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;

View File

@ -1,6 +1,6 @@
package org.warp.picalculator.math.functions.equations;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -29,7 +29,7 @@ public class Equation extends FunctionTwoValues {
}
@Override
protected boolean isSolvable() throws Error {
protected boolean isSolvable() {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
@ -37,52 +37,19 @@ public class Equation extends FunctionTwoValues {
}
@Override
public List<Function> solveOneStep() throws Error {
public ArrayList<Function> solve() throws Error {
if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR);
}
ArrayList<Function> result = new ArrayList<>();
if (variable1.isSolved() & variable2.isSolved()) {
if (((Number)variable2).getTerm().compareTo(new BigInteger("0")) == 0) {
if (variable1.isSolved() & variable2.isSolved()) {
if (((Number)variable2).getTerm().compareTo(new BigDecimal(0)) == 0) {
result.add(this);
} else {
Equation e = new Equation(this.parent, null, null);
e.setVariable1(new Subtraction(e, variable1, variable2));
e.setVariable2(new Number(e, "0"));
result.add(e);
}
} else {
List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>();
if (variable1.isSolved() == false) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1);
}
if (variable2.isSolved() == false) {
l2.addAll(variable2.solveOneStep());
} else {
l2.add(variable2);
}
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) {
result.add(new Equation(this.parent, f[0], f[1]));
result.add(e);
}
}
return result;

View File

@ -1,6 +1,5 @@
package org.warp.picalculator.math.functions.equations;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
import java.util.ArrayList;

View File

@ -1,7 +1,6 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;

View File

@ -1,7 +1,6 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;

View File

@ -1,7 +1,6 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;

View File

@ -1,7 +1,6 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;

View File

@ -1,14 +1,11 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.functions.AnteriorFunction;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Sum;
public class Sine extends AnteriorFunction {

View File

@ -1,7 +1,6 @@
package org.warp.picalculator.math.functions.trigonometry;
import java.util.ArrayList;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathematicalSymbols;

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
* Exponent rule<br>

View File

@ -6,8 +6,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
* Exponent rule<br>

View File

@ -0,0 +1,45 @@
package org.warp.picalculator.math.rules;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Root;
/**
* Exponent rule<br>
* <b>ax=x^1/a</b>
* @author Andrea Cavalli
*
*/
public class ExponentRule16 {
public static boolean compare(Function f) {
if (f instanceof Root) {
Root fnc = (Root) f;
if (fnc.getVariable1().equals(fnc.getVariable2())) {
return true;
}
}
return false;
}
public static ArrayList<Function> execute(Function f) throws Error {
ArrayList<Function> result = new ArrayList<>();
Multiplication fnc = (Multiplication) f;
Power p = new Power(fnc.getParent(), null, null);
Expression expr = new Expression(p);
Function a = fnc.getVariable1().setParent(expr);
expr.addFunctionToEnd(a);
Number two = new Number(p, 2);
p.setVariable1(expr);
p.setVariable2(two);
result.add(p);
return result;
}
}

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
* Exponent rule<br>

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
* Exponent rule<br>

View File

@ -6,8 +6,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
* Exponent rule<br>

View File

@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Number;
/**
* Fractions rule<br>

View File

@ -1,12 +1,11 @@
package org.warp.picalculator.math.rules;
import java.math.BigInteger;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Number;
package org.warp.picalculator.math.rules;
import java.math.BigDecimal;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
/**
@ -21,7 +20,7 @@ public class FractionsRule5 {
Power fnc = (Power) f;
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
Number n2 = (Number) fnc.getVariable2();
if (n2.getTerm().compareTo(BigInteger.ZERO) < 0) {
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
return true;
}
}

View File

@ -5,9 +5,7 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Sum;
/**
* Number rule<br>

View File

@ -5,8 +5,6 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
/**

View File

@ -4,9 +4,9 @@ import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Undefined;
import org.warp.picalculator.math.functions.Number;
/**
* Undefined rule<br>

View File

@ -7,9 +7,8 @@ import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
/**
* Variable rule<br>

View File

@ -7,10 +7,9 @@ import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Variable;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
/**
* Variable rule<br>

View File

@ -7,10 +7,9 @@ import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Variable;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
/**
* Variable rule<br>

View File

@ -1,16 +1,14 @@
package org.warp.picalculator.math.rules.methods;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.util.ArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionTwoValues;
import org.warp.picalculator.math.functions.Negative;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
/**
@ -44,7 +42,7 @@ public class SumMethod1 {
prec = new Subtraction(null, a, ((Negative)b).getVariable());
a.setParent(prec);
((FunctionTwoValues)prec).getVariable2().setParent(prec);
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
prec = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
a.setParent(prec);
((FunctionTwoValues)prec).getVariable2().setParent(prec);
@ -93,11 +91,11 @@ public class SumMethod1 {
Function testFunc;
if (b instanceof Negative) {
testFunc = new Subtraction(null, a, ((Negative)b).getVariable());
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
testFunc = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
} else if (a instanceof Negative) {
testFunc = new Subtraction(null, b, ((Negative)a).getVariable());
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigInteger.ZERO) < 0) {
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
testFunc = new Subtraction(null, b, ((Number)a).multiply(new Number(null, -1)));
} else {
testFunc = new Sum(null, a, b);

View File

@ -1,12 +1,18 @@
package org.warp.picalculator.screens;
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
import static org.warp.picalculator.device.graphicengine.Display.Render.clearcolor;
import static org.warp.picalculator.device.graphicengine.Display.Render.glClearColor;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringRight;
import static org.warp.picalculator.device.graphicengine.Display.Render.glFillRect;
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
import static org.warp.picalculator.device.graphicengine.Display.Render.glSetFont;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
@ -21,7 +27,6 @@ import org.warp.picalculator.device.graphicengine.Screen;
import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.Expression;
public class MathInputScreen extends Screen {
@ -446,11 +451,11 @@ public class MathInputScreen extends Screen {
}
return true;
}
case SURD_MODE:
Calculator.surdMode = !Calculator.surdMode;
case SURD_MODE:
Calculator.exactMode = !Calculator.exactMode;
try {
try {
if (Calculator.surdMode == false) {
if (Calculator.exactMode == false) {
f2 = Calculator.solveExpression(f2);
} else {
equazioneCorrente = "";