From e68e5847b798d17a4d651818a6e55fba45da8a4e Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Wed, 28 Jun 2023 06:26:01 +1000 Subject: fixing crash in neu calculator (#746) fixing crash in calculator --- .../java/io/github/moulberry/notenoughupdates/util/Calculator.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java/io') 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 a58fc8a6..0762d107 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Calculator.java @@ -299,6 +299,11 @@ public class Calculator { Token rightToken = rpnTokens.get(rpnTokens.indexOf(command) - 1); throw new CalculatorException(right + " has a decimal, pick a power that is non-decimal", rightToken.tokenStart, rightToken.tokenLength); } + + if (right.doubleValue() < 0) { + Token rightToken = rpnTokens.get(rpnTokens.indexOf(command) - 1); + throw new CalculatorException(right + " is a negative number, pick a power that is positive", rightToken.tokenStart, rightToken.tokenLength); + } values.push(left.pow(right.intValue()).setScale(2, RoundingMode.HALF_UP)); break; case "x": -- cgit