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:
Explores how to use the rich library of built-in functions for math, string manipulation, and logic within uCalc expressions.
uCalc comes with a comprehensive library of built-in functions that will feel familiar to developers coming from C++, C#, Visual Basic, or spreadsheet applications like Excel. These functions provide the core toolkit for performing mathematical calculations, string manipulation, and logical operations directly within an expression string.
You can call any built-in function by its name, followed by its arguments in parentheses, just as you would in a standard programming language.
csharp
// A simple expression combining math and string functions
uc.EvalStr("Abs(-10) + Length('hello')") // Output: 15
For a complete list of all functions, see the Functions and Operators reference section.
Built-in functions are grouped into several logical categories:
This is the largest category, providing a full suite of trigonometric, logarithmic, rounding, and power functions. It includes everything from basic Abs() and Sqrt() to advanced operations like Tgamma() and Hypot().
Console.WriteLine(uc.Eval("Sin(PI/2) * Pow(2, 10)")); // Output: 1024
This category includes functions for creating, modifying, and inspecting strings. You can perform operations like concatenation (+), finding substrings (IndexOf), changing case (UCase), and more.
Console.WriteLine(uc.EvalStr("SubStr('Hello World', 6, 5)")); // Output: World
This category contains functions for conditional logic, type conversion, and interacting with the engine itself. The most important of these is IIf(), uCalc's equivalent of the ternary operator (condition ? true_part : false_part). It uses lazy evaluation via ByExpr arguments, meaning it only evaluates the branch that is chosen.
Console.WriteLine(uc.EvalStr("IIf(10 > 5, 'Greater', 'Lesser')")); // Output: Greater
The primary advantage is dynamism. In C# or C++, function calls are resolved at compile time. With uCalc, an entire expression, including calls to multiple built-in functions, can be constructed as a string at runtime. This is fundamental for applications where the logic is not known ahead of time, such as:
Avg(sales) * (1 + TAX_RATE) into a text field.While spreadsheet and database languages also have built-in functions, uCalc provides a more complete programming environment. You are not limited to a single formula in a cell or a query. You can define variables, create custom functions, and build complex, multi-step logic that leverages the built-in function library as its foundation.
ID: 1183
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}");
Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}");
Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}");
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}"); Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}"); Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << "Square root of 81 is: " << uc.Eval("Sqrt(81)") << endl;
cout << "Is 10 greater than 5? " << uc.EvalStr("IIf(10 > 5, 'Yes', 'No')") << endl;
cout << "String length: " << uc.Eval("Length('uCalc rocks!')") << endl;
}
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << "Square root of 81 is: " << uc.Eval("Sqrt(81)") << endl; cout << "Is 10 greater than 5? " << uc.EvalStr("IIf(10 > 5, 'Yes', 'No')") << endl; cout << "String length: " << uc.Eval("Length('uCalc rocks!')") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}")
Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}")
Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}")
End Sub
End Module
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}") Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}") Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}") End Sub End Module
ID: 1185
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("a = 10");
uc.DefineVariable("b = 20");
Console.WriteLine($"Before - a: {uc.Eval("a")}, b: {uc.Eval("b")}");
// The built-in Swap() function uses ByHandle to modify variables directly.
uc.Eval("Swap(a, b)");
Console.Write("After - a: "); Console.Write(uc.Eval("a")); Console.Write(", b: "); Console.Write(uc.Eval("b"));
Before - a: 10, b: 20
After - a: 20, b: 10 using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("a = 10"); uc.DefineVariable("b = 20"); Console.WriteLine($"Before - a: {uc.Eval("a")}, b: {uc.Eval("b")}"); // The built-in Swap() function uses ByHandle to modify variables directly. uc.Eval("Swap(a, b)"); Console.Write("After - a: "); Console.Write(uc.Eval("a")); Console.Write(", b: "); Console.Write(uc.Eval("b"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("a = 10");
uc.DefineVariable("b = 20");
cout << "Before - a: " << uc.Eval("a") << ", b: " << uc.Eval("b") << endl;
// The built-in Swap() function uses ByHandle to modify variables directly.
uc.Eval("Swap(a, b)");
cout << "After - a: " << uc.Eval("a") << ", b: " << uc.Eval("b");
}
Before - a: 10, b: 20
After - a: 20, b: 10 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("a = 10"); uc.DefineVariable("b = 20"); cout << "Before - a: " << uc.Eval("a") << ", b: " << uc.Eval("b") << endl; // The built-in Swap() function uses ByHandle to modify variables directly. uc.Eval("Swap(a, b)"); cout << "After - a: " << uc.Eval("a") << ", b: " << uc.Eval("b"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("a = 10")
uc.DefineVariable("b = 20")
Console.WriteLine($"Before - a: {uc.Eval("a")}, b: {uc.Eval("b")}")
'// The built-in Swap() function uses ByHandle to modify variables directly.
uc.Eval("Swap(a, b)")
Console.Write("After - a: ")
Console.Write(uc.Eval("a"))
Console.Write(", b: ")
Console.Write(uc.Eval("b"))
End Sub
End Module
Before - a: 10, b: 20
After - a: 20, b: 10 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("a = 10") uc.DefineVariable("b = 20") Console.WriteLine($"Before - a: {uc.Eval("a")}, b: {uc.Eval("b")}") '// The built-in Swap() function uses ByHandle to modify variables directly. uc.Eval("Swap(a, b)") Console.Write("After - a: ") Console.Write(uc.Eval("a")) Console.Write(", b: ") Console.Write(uc.Eval("b")) End Sub End Module