Skip to content

Commit 2d2cb45

Browse files
authored
Merge pull request #2076 from GGGGeorge-gao/v5-dev
fix Calculator.conversion EmptyStackException bug
2 parents 63fc344 + 18ba850 commit 2d2cb45

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

hutool-core/src/main/java/cn/hutool/core/math/Calculator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private static String transform(String expression) {
191191
}
192192
}
193193
}
194-
if (arr[0] == '~' || (arr.length > 1 && arr[1] == '(')) {
194+
if (arr[0] == '~' && (arr.length > 1 && arr[1] == '(')) {
195195
arr[0] = '-';
196196
return "0" + new String(arr);
197197
} else {

hutool-core/src/test/java/cn/hutool/core/math/CalculatorTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ public void conversationTest4(){
3131
}
3232

3333
@Test
34-
@Ignore
3534
public void conversationTest5(){
3635
// https://github.com/dromara/hutool/issues/1984
3736
final double conversion = Calculator.conversion("((1/1) / (1/1) -1) * 100");
38-
Assert.assertEquals((88D * 66 / 23) % 26, conversion, 2);
37+
Assert.assertEquals(0, conversion, 2);
38+
}
39+
40+
@Test
41+
public void conversationTest6() {
42+
final double conversion = Calculator.conversion("-((2.12-2) * 100)");
43+
Assert.assertEquals(-1D * (2.12 - 2) * 100, conversion, 2);
3944
}
4045
}

0 commit comments

Comments
 (0)