uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Parses and evaluates a string expression in a single step, returning a numeric result.
The double-precision floating-point result of the evaluated expression.
The Eval method provides a convenient one-step shortcut to parse and immediately evaluate an expression, returning its result. It is ideal for scenarios where an expression is evaluated only once and performance is not the primary concern.
EvalEval is the simplest way to get a result from a string. However, it performs two operations internally: parsing and evaluation. If you need to evaluate the same expression multiple times (e.g., in a loop), it is significantly more efficient to use the two-step approach:
Expression object.This avoids the overhead of re-parsing the string on every iteration.
This function is specifically designed for expressions that yield a simple numeric result. It always returns a double.
Int32 or Boolean), the value will be converted to a double.String or Complex number), the return value will be meaningless. No error is raised in this case.For expressions that return non-numeric types or to get a string representation of any result, use the more versatile uCalc.EvalStr method instead.
The expression string can contain any combination of numbers, variables, and calls to built-in or user-defined Functions and Operators.
DataTable.Compute: A common workaround in .NET for evaluating strings is using the Compute method of a DataTable. While it works for simple arithmetic, it is far less powerful, significantly slower, and lacks the rich feature set of uCalc (custom functions, complex numbers, transformers, etc.).Evaluate() methods. uCalc's Eval differentiates itself by being part of a much larger, cohesive engine. The expression can leverage custom data types, operators, and transformation rules defined within the same uCalc instance, offering greater flexibility and power than single-purpose evaluation libraries.Parse + Evaluate: As mentioned, Eval is for convenience. The two-step process is for performance-critical applications.ID: 334
using uCalcSoftware;
var uc = new uCalc();
// Eval provides a direct way to compute results from strings.
Console.WriteLine(uc.Eval("1+1"));
Console.WriteLine(uc.Eval("5*(3+9)^2"));
Console.WriteLine(uc.Eval("Sqrt(16) + Sin(0)"));
Console.WriteLine(uc.Eval("Length('This is a test')"));
2
720
4
14 using uCalcSoftware; var uc = new uCalc(); // Eval provides a direct way to compute results from strings. Console.WriteLine(uc.Eval("1+1")); Console.WriteLine(uc.Eval("5*(3+9)^2")); Console.WriteLine(uc.Eval("Sqrt(16) + Sin(0)")); Console.WriteLine(uc.Eval("Length('This is a test')"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Eval provides a direct way to compute results from strings.
cout << uc.Eval("1+1") << endl;
cout << uc.Eval("5*(3+9)^2") << endl;
cout << uc.Eval("Sqrt(16) + Sin(0)") << endl;
cout << uc.Eval("Length('This is a test')") << endl;
}
2
720
4
14 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Eval provides a direct way to compute results from strings. cout << uc.Eval("1+1") << endl; cout << uc.Eval("5*(3+9)^2") << endl; cout << uc.Eval("Sqrt(16) + Sin(0)") << endl; cout << uc.Eval("Length('This is a test')") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Eval provides a direct way to compute results from strings.
Console.WriteLine(uc.Eval("1+1"))
Console.WriteLine(uc.Eval("5*(3+9)^2"))
Console.WriteLine(uc.Eval("Sqrt(16) + Sin(0)"))
Console.WriteLine(uc.Eval("Length('This is a test')"))
End Sub
End Module
2
720
4
14 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Eval provides a direct way to compute results from strings. Console.WriteLine(uc.Eval("1+1")) Console.WriteLine(uc.Eval("5*(3+9)^2")) Console.WriteLine(uc.Eval("Sqrt(16) + Sin(0)")) Console.WriteLine(uc.Eval("Length('This is a test')")) End Sub End Module
ID: 335
using uCalcSoftware;
var uc = new uCalc();
// Define variables representing configuration or user inputs.
uc.DefineVariable("principal = 20000");
uc.DefineVariable("annual_rate = 0.0575");
uc.DefineVariable("years = 4");
// Evaluate an expression combining these variables.
var interest = uc.Eval("principal * annual_rate * years");
Console.WriteLine($"Total Interest: {interest}");
Total Interest: 4600 using uCalcSoftware; var uc = new uCalc(); // Define variables representing configuration or user inputs. uc.DefineVariable("principal = 20000"); uc.DefineVariable("annual_rate = 0.0575"); uc.DefineVariable("years = 4"); // Evaluate an expression combining these variables. var interest = uc.Eval("principal * annual_rate * years"); Console.WriteLine($"Total Interest: {interest}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define variables representing configuration or user inputs.
uc.DefineVariable("principal = 20000");
uc.DefineVariable("annual_rate = 0.0575");
uc.DefineVariable("years = 4");
// Evaluate an expression combining these variables.
auto interest = uc.Eval("principal * annual_rate * years");
cout << "Total Interest: " << interest << endl;
}
Total Interest: 4600 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define variables representing configuration or user inputs. uc.DefineVariable("principal = 20000"); uc.DefineVariable("annual_rate = 0.0575"); uc.DefineVariable("years = 4"); // Evaluate an expression combining these variables. auto interest = uc.Eval("principal * annual_rate * years"); cout << "Total Interest: " << interest << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define variables representing configuration or user inputs.
uc.DefineVariable("principal = 20000")
uc.DefineVariable("annual_rate = 0.0575")
uc.DefineVariable("years = 4")
'// Evaluate an expression combining these variables.
Dim interest = uc.Eval("principal * annual_rate * years")
Console.WriteLine($"Total Interest: {interest}")
End Sub
End Module
Total Interest: 4600 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define variables representing configuration or user inputs. uc.DefineVariable("principal = 20000") uc.DefineVariable("annual_rate = 0.0575") uc.DefineVariable("years = 4") '// Evaluate an expression combining these variables. Dim interest = uc.Eval("principal * annual_rate * years") Console.WriteLine($"Total Interest: {interest}") End Sub End Module
ID: 21
using uCalcSoftware;
var uc = new uCalc();
// See EvalStr for more examples.
Console.WriteLine(uc.Eval("1+1"));
Console.WriteLine(uc.Eval("5*(3+9)^2"));
Console.WriteLine(uc.Eval("Length('This is a test')"));
2
720
14 using uCalcSoftware; var uc = new uCalc(); // See EvalStr for more examples. Console.WriteLine(uc.Eval("1+1")); Console.WriteLine(uc.Eval("5*(3+9)^2")); Console.WriteLine(uc.Eval("Length('This is a test')"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// See EvalStr for more examples.
cout << uc.Eval("1+1") << endl;
cout << uc.Eval("5*(3+9)^2") << endl;
cout << uc.Eval("Length('This is a test')") << endl;
}
2
720
14 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // See EvalStr for more examples. cout << uc.Eval("1+1") << endl; cout << uc.Eval("5*(3+9)^2") << endl; cout << uc.Eval("Length('This is a test')") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// See EvalStr for more examples.
Console.WriteLine(uc.Eval("1+1"))
Console.WriteLine(uc.Eval("5*(3+9)^2"))
Console.WriteLine(uc.Eval("Length('This is a test')"))
End Sub
End Module
2
720
14 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// See EvalStr for more examples. Console.WriteLine(uc.Eval("1+1")) Console.WriteLine(uc.Eval("5*(3+9)^2")) Console.WriteLine(uc.Eval("Length('This is a test')")) End Sub End Module
ID: 296
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("x = 5");
uc.DefineFunction("Area(length, width) = length * width");
Console.WriteLine(uc.Eval("Area(4, x) + 7"));
27 using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("x = 5"); uc.DefineFunction("Area(length, width) = length * width"); Console.WriteLine(uc.Eval("Area(4, x) + 7"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("x = 5");
uc.DefineFunction("Area(length, width) = length * width");
cout << uc.Eval("Area(4, x) + 7") << endl;
}
27 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 5"); uc.DefineFunction("Area(length, width) = length * width"); cout << uc.Eval("Area(4, x) + 7") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x = 5")
uc.DefineFunction("Area(length, width) = length * width")
Console.WriteLine(uc.Eval("Area(4, x) + 7"))
End Sub
End Module
27 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x = 5") uc.DefineFunction("Area(length, width) = length * width") Console.WriteLine(uc.Eval("Area(4, x) + 7")) End Sub End Module
ID: 1296
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("x = 10");
uc.DefineFunction("DoubleThis(n) = n * 2");
Console.WriteLine(uc.Eval("DoubleThis(x) + 5"));
25 using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("x = 10"); uc.DefineFunction("DoubleThis(n) = n * 2"); Console.WriteLine(uc.Eval("DoubleThis(x) + 5"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("x = 10");
uc.DefineFunction("DoubleThis(n) = n * 2");
cout << uc.Eval("DoubleThis(x) + 5") << endl;
}
25 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 10"); uc.DefineFunction("DoubleThis(n) = n * 2"); cout << uc.Eval("DoubleThis(x) + 5") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x = 10")
uc.DefineFunction("DoubleThis(n) = n * 2")
Console.WriteLine(uc.Eval("DoubleThis(x) + 5"))
End Sub
End Module
25 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x = 10") uc.DefineFunction("DoubleThis(n) = n * 2") Console.WriteLine(uc.Eval("DoubleThis(x) + 5")) End Sub End Module
ID: 297
using uCalcSoftware;
var uc = new uCalc();
static void MyAreaCallback(uCalc.Callback cb) {
var length = cb.Arg(1);
var width = cb.Arg(2);
cb.Return(length * width);
}
// The signature is defined, but the logic is provided by 'MyAreaCallback'.
uc.DefineFunction("Area(x, y)", MyAreaCallback);
Console.WriteLine(uc.Eval("Area(3, 4)"));
12 using uCalcSoftware; var uc = new uCalc(); static void MyAreaCallback(uCalc.Callback cb) { var length = cb.Arg(1); var width = cb.Arg(2); cb.Return(length * width); } // The signature is defined, but the logic is provided by 'MyAreaCallback'. uc.DefineFunction("Area(x, y)", MyAreaCallback); Console.WriteLine(uc.Eval("Area(3, 4)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyAreaCallback(uCalcBase::Callback cb) {
auto length = cb.Arg(1);
auto width = cb.Arg(2);
cb.Return(length * width);
}
int main() {
uCalc uc;
// The signature is defined, but the logic is provided by 'MyAreaCallback'.
uc.DefineFunction("Area(x, y)", MyAreaCallback);
cout << uc.Eval("Area(3, 4)") << endl;
}
12 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyAreaCallback(uCalcBase::Callback cb) { auto length = cb.Arg(1); auto width = cb.Arg(2); cb.Return(length * width); } int main() { uCalc uc; // The signature is defined, but the logic is provided by 'MyAreaCallback'. uc.DefineFunction("Area(x, y)", MyAreaCallback); cout << uc.Eval("Area(3, 4)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyAreaCallback(ByVal cb As uCalc.Callback)
Dim length = cb.Arg(1)
Dim width = cb.Arg(2)
cb.Return(length * width)
End Sub
Public Sub Main()
Dim uc As New uCalc()
'// The signature is defined, but the logic is provided by 'MyAreaCallback'.
uc.DefineFunction("Area(x, y)", AddressOf MyAreaCallback)
Console.WriteLine(uc.Eval("Area(3, 4)"))
End Sub
End Module
12 Imports System Imports uCalcSoftware Public Module Program Public Sub MyAreaCallback(ByVal cb As uCalc.Callback) Dim length = cb.Arg(1) Dim width = cb.Arg(2) cb.Return(length * width) End Sub Public Sub Main() Dim uc As New uCalc() '// The signature is defined, but the logic is provided by 'MyAreaCallback'. uc.DefineFunction("Area(x, y)", AddressOf MyAreaCallback) Console.WriteLine(uc.Eval("Area(3, 4)")) End Sub End Module