Skip to content

Commit

Permalink
fix(evaluator): Fix power
Browse files Browse the repository at this point in the history
Signed-off-by: Myzel394 <[email protected]>
  • Loading branch information
Myzel394 committed Jul 21, 2024
1 parent b53a0b1 commit 33293a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Expression(
if (moveIfMatched(Token.Operator.power)) {
val factor = parseFactor()

if (factor.compareTo(BigDecimal.ZERO) == 0) {
if (factor.compareTo(BigDecimal.ZERO) == 0 && expr.compareTo(BigDecimal.ZERO) == 0) {
throw ExpressionException.BadExpression()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ExpressionSimpleTest {
fun zeroExponent() = assertExpr("5^0", "1")

@Test
fun negativeExponent() = assertExpr("5^-1", "0.2")
fun negativeExponent() = assertExpr("5^(-2)", "0.04")

@Test
fun trigonometricLimits() = assertExpr("sin(0)", "0")
Expand Down

0 comments on commit 33293a4

Please sign in to comment.