mparlak / Flee

Fast Lightweight Expression Evaluator
607 stars 119 forks source link

sqrt math function is not working #81

Open ramakrishnareddy2108 opened 3 years ago

ramakrishnareddy2108 commented 3 years ago

getting 'FunctionCallElement: Could find not function 'sqrt(Int32)'' error while using sqrt math operator

hunkydoryrepair commented 3 years ago

sqrt takes a double as an argument, but it should convert for you. I created a test and it passes without issue, so provide code/expression if this is still an issue:


            ExpressionContext context = new ExpressionContext();
            context.Imports.AddType(typeof(Math));
            IDynamicExpression e1 = context.CompileDynamic("sqrt(16)");

            Assert.AreEqual(4.0, e1.Evaluate());
da-sann commented 2 years ago

Following code will return Flee.PublicTypes.ExpressionCompileException: 'FunctionCallElement: Could find not function 'sqrt(Decimal)''

        ExpressionContext context = new ExpressionContext();
        context.Imports.AddType(typeof(Math));
        context.Variables["a"] = Convert.ToDecimal(199);
        IDynamicExpression eDynamic = context.CompileDynamic("sqrt(a) + pi");
        var result = eDynamic.Evaluate();
shawndewet commented 1 year ago

Odd, it passes on my system.