Power function in Microsoft.CSharpScript.CodeAnalysis C#

Hemanth B 886 Reputation points
2022-01-14T07:46:12.627+00:00

Is there any way where I can evaluate for example 4^6 in Microsoft.CSharpScript.CodeAnalysis without using Math.Pow?

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-01-17T02:19:57.387+00:00

    @Hemanth B , based on my research, it is hard to find a method to replace the Math.Pow function because there is no power operator in C#.

    Currently, I only could use the following code to get the result for "4^6".

     static async Task<double> EvaluateFormulaAsync(string formula)  
            {  
                return await CSharpScript.EvaluateAsync<double>(formula, ScriptOptions.Default.WithImports("System.Math"));  
            }  
            static void Main(string[] args)  
            {  
                var result = EvaluateFormulaAsync("System.Math.Pow(4, 6)").Result;  
                Console.WriteLine(result);  
            }  
    

    Result:

    165387-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.