fix substraction bug
This commit is contained in:
parent
be3ed51907
commit
2a9918ffb5
|
|
@ -1,6 +1,6 @@
|
||||||
public class Calculator {
|
public class Calculator {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String expr = "(36 * 3 + 9 * 7) * (84 / 12) * 5";
|
String expr = "(84 / 4 * 3 - 9) * 2 + 1 / 5"; // 108.2
|
||||||
Parser p = new Parser(expr);
|
Parser p = new Parser(expr);
|
||||||
String postfix = p.toPostFix();
|
String postfix = p.toPostFix();
|
||||||
System.out.println(p.evalExpr(postfix));
|
System.out.println(p.evalExpr(postfix));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
/* Todo
|
/* Todo
|
||||||
* - Fix Substraction errors
|
|
||||||
* - Add support for trigonometric functions
|
* - Add support for trigonometric functions
|
||||||
* - Remove all edge cases
|
* - Remove all edge cases
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,6 +16,7 @@ public class Parser {
|
||||||
|
|
||||||
public static boolean isOperand(char c) {
|
public static boolean isOperand(char c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
case '3':
|
case '3':
|
||||||
|
|
@ -115,7 +115,7 @@ public class Parser {
|
||||||
case '+':
|
case '+':
|
||||||
return op2 + op1;
|
return op2 + op1;
|
||||||
case '-':
|
case '-':
|
||||||
return op2 - op1;
|
return op1 - op2;
|
||||||
case '*':
|
case '*':
|
||||||
return op2 * op1;
|
return op2 * op1;
|
||||||
case '/':
|
case '/':
|
||||||
|
|
|
||||||
Reference in New Issue