Skip to content

Commit

Permalink
Fix exponentiation at NCalc.Async (ncalc#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
gumbarros authored Oct 7, 2024
1 parent 3309993 commit 3465c99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/NCalc.Async/Visitors/AsyncEvaluationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public class AsyncEvaluationVisitor(AsyncExpressionContext context) : ILogicalEx

case BinaryExpressionType.Exponentiation:
{
return MathHelper.Pow(left.Value, right.Value, context);
var rightValue = await right.Value;
var leftValue = await left.Value;
return MathHelper.Pow(leftValue, rightValue, context);
}

case BinaryExpressionType.In:
Expand Down
6 changes: 6 additions & 0 deletions test/NCalc.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,10 @@ public async Task ShouldEvaluateTernaryAsync()
{
Assert.Equal(42, await new AsyncExpression("1 == 1 ? 42 : 3/0").EvaluateAsync());
}

[Fact]
public async Task ShouldEvaluatePowAsync()
{
Assert.Equal(4d, await new AsyncExpression("2**2").EvaluateAsync());
}
}

0 comments on commit 3465c99

Please sign in to comment.