Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VisitInit and Safediv function #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/NCalcAsync/Domain/EvaluationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ public override async Task VisitAsync(Function function)
switch (function.Identifier.Name.ToLower())
{
#region Specifics
case "value":
await VisitValue(function);
break;
case "init":
await VisitInit(function);
break;
Expand Down Expand Up @@ -524,6 +527,27 @@ await EvaluateAsync(function.Expressions[0]))

#endregion

#region Safediv
case "safediv":

CheckCase("Safediv", function.Identifier.Name);

if (function.Expressions.Length > 3 && function.Expressions.Length < 2)
throw new ArgumentException("Sign() takes exactly 3 arguments");

if (function.Expressions.Length == 3)
{
if (Convert.ToDouble(await EvaluateAsync(function.Expressions[1])) == 0)
{
Result = Convert.ToDouble(await EvaluateAsync(function.Expressions[0])) / Convert.ToDouble(await EvaluateAsync(function.Expressions[2]));
} else
{
Result = Convert.ToDouble(await EvaluateAsync(function.Expressions[0])) / Convert.ToDouble(await EvaluateAsync(function.Expressions[1]));
}
} else { Result = 0; }
break;
#endregion

#region Sign
case "sign":

Expand Down