Introduction

Problem

You need to resolve an arithmetic/mathematic dynamic expression using the power operator at runtime.

Solution

The Eval-Expression.NET support the power operator ‘^^’ (double caret).

You can also force the caret character ‘^’ to by treated as an exponent with the UseCaretForExponent configuration.

Example – Expression with ‘Power’ operator

// using Z.Expressions; // Don't forget to include this.

var result = Eval.Execute("2^^3"); // return 8;

Example – Modifyng the Exclusive-OR with Power Operator

// using Z.Expressions; // Don't forget to include this.

EvalManager.DefaultContext.UseCaretForExponent = true;
var result = Eval.Execute("2^3"); // return 8;

Example – Expression with Parameter

// using Z.Expressions; // Don't forget to include this.

var result = Eval.Execute("X^^Y", new { X = 2, Y = 3 }); // return 8;