aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2022-10-21 18:58:47 +0200
committerGitHub <noreply@github.com>2022-10-21 18:58:47 +0200
commit3168a7560a4d8f1d29c8f2518d674c1f4c85ef8c (patch)
treeb7576e32aefacd06cca005fcc1284643dcfa2ad8 /src
parent742cbb2aed8e45873fdb06366b437d277d019957 (diff)
downloadNotEnoughUpdates-3168a7560a4d8f1d29c8f2518d674c1f4c85ef8c.tar.gz
NotEnoughUpdates-3168a7560a4d8f1d29c8f2518d674c1f4c85ef8c.tar.bz2
NotEnoughUpdates-3168a7560a4d8f1d29c8f2518d674c1f4c85ef8c.zip
Fix calculator crash by using correct apis (#391)
Right the wrongs
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
index b39a05f4..221b5023 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java
@@ -101,6 +101,10 @@ public class Calculator {
token.tokenLength = 1;
token.type = TokenType.BINOP;
token.operatorValue = c + "";
+ if (c == '*' && i + 1 < source.length() && source.charAt(i + 1) == '*') {
+ token.tokenLength++;
+ token.operatorValue = "^";
+ }
} else if (postops.indexOf(c) != -1) {
token.tokenLength = 1;
token.type = TokenType.POSTOP;
@@ -162,7 +166,6 @@ public class Calculator {
Deque<Token> op = new ArrayDeque<>();
List<Token> out = new ArrayList<>();
- boolean nextMultiplyShouldBePower = false;
for (Token currentlyShunting : toShunt) {
switch (currentlyShunting.type) {
@@ -170,17 +173,6 @@ public class Calculator {
out.add(currentlyShunting);
break;
case BINOP:
- Token next = toShunt.get(toShunt.indexOf(currentlyShunting) + 1);
- if (currentlyShunting.operatorValue.equals("^")) {
- if (next.numericValue > 999) {
- throw new CalculatorException(next.numericValue + " is too large, pick a power less than 1000", next.tokenStart, next.tokenLength);
- }
- } else if (next != null && currentlyShunting.operatorValue.equals("*") && next.operatorValue != null && next.operatorValue.equals("*")) {
- nextMultiplyShouldBePower = true;
- continue;
- } else if (nextMultiplyShouldBePower && currentlyShunting.operatorValue.equals("*")) {
- currentlyShunting.operatorValue = "^";
- }
int p = getPrecedence(currentlyShunting);
while (!op.isEmpty()) {
Token l = op.peek();