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:
An overview of uCalc's high-performance expression evaluation engine, highlighting its features, use cases, and dynamic capabilities.
The uCalc Fast Math Parser is a high-performance, embeddable engine that brings the power of a dynamic scripting language to your application. It allows you to parse and evaluate mathematical, logical, and string-based expressions provided as plain text at runtime. It's not just a calculator; it's a complete, sandboxed language environment that you can customize and extend on the fly.
This overview covers the core advantages that make the uCalc expression parser a superior choice for a wide range of applications, from financial modeling and scientific computing to game scripting and dynamic report generation.
The single most important architectural feature for performance is the separation of parsing and evaluation. While convenience methods like EvalStr are great for one-off calculations, true performance is achieved by parsing an expression once and evaluating it many times.
By calling Parse outside a loop and Evaluate inside, you can achieve execution speeds that approach native compiled code.
A common workaround for evaluating strings in .NET is DataTable.Compute. This method is notoriously slow because it must re-parse the expression string on every single call, making it completely unsuitable for performance-critical loops. uCalc's two-step model provides a C#-accessible engine with C++-level performance.
Unlike compiled languages where the syntax is fixed, uCalc's grammar is fully extensible at runtime. You can teach the engine new tricks without recompiling your application.
"InToCm(x) = x * 2.54") or by binding to high-performance native code in your application.In C# or C++, the language's syntax is immutable. With uCalc, you can load new function and operator definitions from configuration files, user scripts, or a database at startup, allowing your application to adapt its own syntax on the fly.
Many scripting languages (like Python or JavaScript) include a built-in eval() function. While powerful, these functions often pose a major security risk because they can execute arbitrary code, potentially accessing the file system or network.
eval())The uCalc engine is a secure sandbox. An expression can only access the functions, operators, and variables that you have explicitly defined within its instance. It has no intrinsic ability to interact with the host operating system, which prevents code injection vulnerabilities and ensures that user-provided formulas can be evaluated safely.
Out of the box, the parser includes a comprehensive library of over 100 built-in Functions and Operators, including:
SubStr, UCase, Trim, etc.).IIf (a lazily-evaluated ternary operator).ID: 1266
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32"));
98.6 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.EvalStr("(37) * (9 / 5) + 32") << endl;
}
98.6 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.EvalStr("(37) * (9 / 5) + 32") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32"))
End Sub
End Module
98.6 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32")) End Sub End Module
ID: 1267
using uCalcSoftware;
var uc = new uCalc();
// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100");
// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate
uc.DefineVariable("periods = 30 * 12"); // 30 years
uc.DefineVariable("loan_amount = 200000"); // $200,000
Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"));
1073.64 using uCalcSoftware; var uc = new uCalc(); // Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100"); // Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate uc.DefineVariable("periods = 30 * 12"); // 30 years uc.DefineVariable("loan_amount = 200000"); // $200,000 Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100");
// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate
uc.DefineVariable("periods = 30 * 12"); // 30 years
uc.DefineVariable("loan_amount = 200000"); // $200,000
cout << uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)") << endl;
}
1073.64 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100"); // Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate uc.DefineVariable("periods = 30 * 12"); // 30 years uc.DefineVariable("loan_amount = 200000"); // $200,000 cout << uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100")
'// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12") '// 5% annual rate
uc.DefineVariable("periods = 30 * 12") '// 30 years
uc.DefineVariable("loan_amount = 200000") '// $200,000
Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"))
End Sub
End Module
1073.64 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100") '// Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12") '// 5% annual rate uc.DefineVariable("periods = 30 * 12") '// 30 years uc.DefineVariable("loan_amount = 200000") '// $200,000 Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)")) End Sub End Module
ID: 31
using uCalcSoftware;
var uc = new uCalc();
var VariableX = uc.DefineVariable("x");
var Expression = "x^2 * 10"; // Replace this with your expression
Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---");
var ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
Console.WriteLine(ParsedExpr.Evaluate());
}
ParsedExpr.Release();
VariableX.Release();
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 using uCalcSoftware; var uc = new uCalc(); var VariableX = uc.DefineVariable("x"); var Expression = "x^2 * 10"; // Replace this with your expression Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---"); var ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { VariableX.Value(x); Console.WriteLine(ParsedExpr.Evaluate()); } ParsedExpr.Release(); VariableX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto VariableX = uc.DefineVariable("x");
auto Expression = "x^2 * 10"; // Replace this with your expression
cout << "--- Efficient: Parse() once, then Evaluate() in a loop ---" << endl;
auto ParsedExpr = uc.Parse(Expression);
for (double x = 1; x <= 10; x++) {
VariableX.Value(x);
cout << ParsedExpr.Evaluate() << endl;
}
ParsedExpr.Release();
VariableX.Release();
}
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto VariableX = uc.DefineVariable("x"); auto Expression = "x^2 * 10"; // Replace this with your expression cout << "--- Efficient: Parse() once, then Evaluate() in a loop ---" << endl; auto ParsedExpr = uc.Parse(Expression); for (double x = 1; x <= 10; x++) { VariableX.Value(x); cout << ParsedExpr.Evaluate() << endl; } ParsedExpr.Release(); VariableX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim VariableX = uc.DefineVariable("x")
Dim Expression = "x^2 * 10" '// Replace this with your expression
Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---")
Dim ParsedExpr = uc.Parse(Expression)
For x As Double = 1 To 10
VariableX.Value(x)
Console.WriteLine(ParsedExpr.Evaluate())
Next
ParsedExpr.Release()
VariableX.Release()
End Sub
End Module
--- Efficient: Parse() once, then Evaluate() in a loop ---
10
40
90
160
250
360
490
640
810
1000 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim VariableX = uc.DefineVariable("x") Dim Expression = "x^2 * 10" '// Replace this with your expression Console.WriteLine("--- Efficient: Parse() once, then Evaluate() in a loop ---") Dim ParsedExpr = uc.Parse(Expression) For x As Double = 1 To 10 VariableX.Value(x) Console.WriteLine(ParsedExpr.Evaluate()) Next ParsedExpr.Release() VariableX.Release() End Sub End Module