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:
Retrieves a numeric argument passed to a callback function, returned as a double-precision float.
The value of the specified argument, converted to a double-precision floating-point number.
The Arg method retrieves a numeric argument that was passed to a callback function, returning it as a double.
When a function or operator is defined using a callback with DefineFunction or DefineOperator, this method is the primary way to access the values of its arguments from within your host application's code.
Unlike most C-family languages that use 0-based indexing for arrays and lists, uCalc callback arguments are 1-based. The first argument is at index 1, the second is at index 2, and so on. This is a crucial distinction to avoid off-by-one errors.
1 and the right operand is at index 2.1.For convenience, you can also use the parameterless Arg1() and Arg2() methods, which are slightly more efficient.
Arg() is the default getter for double values and is functionally identical to ArgDbl(). If your callback expects arguments of other types, you should use the corresponding type-specific methods for clarity and to avoid unnecessary conversions:
ArgInt32() for 32-bit integers.ArgStr() for strings.ArgBool() for booleans.In native C++ or C#, retrieving arguments from a callback often involves variadic templates, va_list, or parameter arrays (params object[]), which can add complexity. uCalc's Callback object provides a simple, unified interface (cb.Arg(1), cb.ArgStr(2), etc.) that abstracts away these differences, providing a consistent API across all supported languages. This model simplifies the process of retrieving arguments, especially for functions with a variable number of arguments.
ID: 12
using uCalcSoftware;
var uc = new uCalc();
static void MyAverage(uCalc.Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
uc.DefineFunction("Average(x ...)", MyAverage);
Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"));
6 using uCalcSoftware; var uc = new uCalc(); static void MyAverage(uCalc.Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } uc.DefineFunction("Average(x ...)", MyAverage); Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyAverage(uCalcBase::Callback cb) {
double Total = 0;
for (int x = 1; x <= cb.ArgCount(); x++) {
Total = Total + cb.Arg(x);
}
cb.Return(Total / cb.ArgCount());
}
int main() {
uCalc uc;
uc.DefineFunction("Average(x ...)", MyAverage);
cout << uc.Eval("Average(10, 3, 7, 4)") << endl;
}
6 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyAverage(uCalcBase::Callback cb) { double Total = 0; for (int x = 1; x <= cb.ArgCount(); x++) { Total = Total + cb.Arg(x); } cb.Return(Total / cb.ArgCount()); } int main() { uCalc uc; uc.DefineFunction("Average(x ...)", MyAverage); cout << uc.Eval("Average(10, 3, 7, 4)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyAverage(ByVal cb As uCalc.Callback)
Dim Total As Double = 0
For x As Integer = 1 To cb.ArgCount()
Total = Total + cb.Arg(x)
Next
cb.Return(Total / cb.ArgCount())
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineFunction("Average(x ...)", AddressOf MyAverage)
Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)"))
End Sub
End Module
6 Imports System Imports uCalcSoftware Public Module Program Public Sub MyAverage(ByVal cb As uCalc.Callback) Dim Total As Double = 0 For x As Integer = 1 To cb.ArgCount() Total = Total + cb.Arg(x) Next cb.Return(Total / cb.ArgCount()) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineFunction("Average(x ...)", AddressOf MyAverage) Console.WriteLine(uc.Eval("Average(10, 3, 7, 4)")) 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
ID: 14
using uCalcSoftware;
var uc = new uCalc();
static void MySum(uCalc.Callback cb) {
var Total = 0.0;
var Expr = cb.ArgExpr(1);
var Start = cb.Arg(2);
var Finish = cb.Arg(3);
var Variable = cb.ArgItem(4);
for (double x = Start; x <= Finish; x++) {
Variable.Value(x);
Total += Expr.Evaluate();
}
cb.Return(Total);
}
uc.DefineVariable("x");
uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", MySum);
Console.WriteLine(uc.Eval("Sum(x ^ 2, 1, 10, x)"));
385 using uCalcSoftware; var uc = new uCalc(); static void MySum(uCalc.Callback cb) { var Total = 0.0; var Expr = cb.ArgExpr(1); var Start = cb.Arg(2); var Finish = cb.Arg(3); var Variable = cb.ArgItem(4); for (double x = Start; x <= Finish; x++) { Variable.Value(x); Total += Expr.Evaluate(); } cb.Return(Total); } uc.DefineVariable("x"); uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", MySum); Console.WriteLine(uc.Eval("Sum(x ^ 2, 1, 10, x)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MySum(uCalcBase::Callback cb) {
auto Total = 0.0;
auto Expr = cb.ArgExpr(1);
auto Start = cb.Arg(2);
auto Finish = cb.Arg(3);
auto Variable = cb.ArgItem(4);
for (double x = Start; x <= Finish; x++) {
Variable.Value(x);
Total += Expr.Evaluate();
}
cb.Return(Total);
}
int main() {
uCalc uc;
uc.DefineVariable("x");
uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", MySum);
cout << uc.Eval("Sum(x ^ 2, 1, 10, x)") << endl;
}
385 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MySum(uCalcBase::Callback cb) { auto Total = 0.0; auto Expr = cb.ArgExpr(1); auto Start = cb.Arg(2); auto Finish = cb.Arg(3); auto Variable = cb.ArgItem(4); for (double x = Start; x <= Finish; x++) { Variable.Value(x); Total += Expr.Evaluate(); } cb.Return(Total); } int main() { uCalc uc; uc.DefineVariable("x"); uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", MySum); cout << uc.Eval("Sum(x ^ 2, 1, 10, x)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MySum(ByVal cb As uCalc.Callback)
Dim Total = 0.0
Dim Expr = cb.ArgExpr(1)
Dim Start = cb.Arg(2)
Dim Finish = cb.Arg(3)
Dim Variable = cb.ArgItem(4)
For x As Double = Start To Finish
Variable.Value(x)
Total += Expr.Evaluate()
Next
cb.Return(Total)
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x")
uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", AddressOf MySum)
Console.WriteLine(uc.Eval("Sum(x ^ 2, 1, 10, x)"))
End Sub
End Module
385 Imports System Imports uCalcSoftware Public Module Program Public Sub MySum(ByVal cb As uCalc.Callback) Dim Total = 0.0 Dim Expr = cb.ArgExpr(1) Dim Start = cb.Arg(2) Dim Finish = cb.Arg(3) Dim Variable = cb.ArgItem(4) For x As Double = Start To Finish Variable.Value(x) Total += Expr.Evaluate() Next cb.Return(Total) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x") uc.DefineFunction("Sum(ByExpr Expr, Start, Finish, ByHandle Var)", AddressOf MySum) Console.WriteLine(uc.Eval("Sum(x ^ 2, 1, 10, x)")) End Sub End Module