uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

Arg

Method

Product: 

Fast Math Parser

Class: 

Callback

Retrieves a numeric argument passed to a callback function, returned as a double-precision float.

Syntax

Arg(int)

Parameters

index
int
The 1-based index of the argument to retrieve. The first argument is at index 1.

Return

double

The value of the specified argument, converted to a double-precision floating-point number.

Remarks

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.

⚠️ 1-Based Indexing

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.

  • For a binary operator, the left operand is at index 1 and the right operand is at index 2.
  • For a unary operator, the single operand is at index 1.

For convenience, you can also use the parameterless Arg1() and Arg2() methods, which are slightly more efficient.

🎯 Type-Specific Alternatives

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.
  • ... and so on for other supported types.

💡 Comparative Analysis

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.

Examples

Defining a callback function with a variable number of arguments
				
					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
				
					#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;
}
				
			
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
				
			
6