From 766dcdb05d1fb329e4020f0c6a321644eecf55fd Mon Sep 17 00:00:00 2001 From: KessalR <72248648+KessalR@users.noreply.github.com> Date: Wed, 7 Apr 2021 17:15:40 +0200 Subject: [PATCH 1/2] Update EvaluationVisitor.cs case "value" added --- src/NCalcAsync/Domain/EvaluationVisitor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NCalcAsync/Domain/EvaluationVisitor.cs b/src/NCalcAsync/Domain/EvaluationVisitor.cs index 3d97511..521de66 100644 --- a/src/NCalcAsync/Domain/EvaluationVisitor.cs +++ b/src/NCalcAsync/Domain/EvaluationVisitor.cs @@ -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; From ee517daccf98a6c4d611936eec2fabb4769c6484 Mon Sep 17 00:00:00 2001 From: clementdepond <70962478+clementdepond@users.noreply.github.com> Date: Tue, 4 May 2021 15:35:54 +0200 Subject: [PATCH 2/2] Update EvaluationVisitor.cs --- src/NCalcAsync/Domain/EvaluationVisitor.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/NCalcAsync/Domain/EvaluationVisitor.cs b/src/NCalcAsync/Domain/EvaluationVisitor.cs index 3d97511..dded5c5 100644 --- a/src/NCalcAsync/Domain/EvaluationVisitor.cs +++ b/src/NCalcAsync/Domain/EvaluationVisitor.cs @@ -524,6 +524,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":