Return

Method

Sets the double-precision floating-point return value for a custom function or operator implemented via callback.

Product: 

Class: 

Warning

uCalc API Preview Release Notice:The uCalc engine has successfully transitioned to modern cross-platform environments.The next phase envolves some structural changes, performance optimizations, and API refinements.The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.

Syntax

Return(double)

Parameters

value
double
The double-precision value to be returned from the callback to the uCalc engine.

Return

void

This method does not return a value.

Remarks

The Return method (or synonymous ReturnDbl) is the primary mechanism for sending a double result from a native callback function back to the uCalc evaluation engine. When a custom function or operator is called within an expression, this method must be used to provide its output.

Type-Specific Returns

This method is specifically for returning double values. uCalc provides a family of type-safe return methods for other data types. Using the correct method ensures data integrity and avoids unnecessary type conversions.

Comparative Analysis

Unlike a native return statement in C# or C++, which is a language-level control flow keyword, cb.Return() is a method call that interacts with the uCalc engine's internal state. It effectively places the provided value onto the evaluation stack, allowing the engine to continue processing the expression. This distinction is crucial: the callback function itself is typically void in the host language, and cb.Return() is the designated channel for communicating results back to the parser.

Examples

Defining a callback function 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
				
					#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
Demonstrates defining a function that is implemented by a native callback in the host application.

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
				
					#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;
}
				
			
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
				
			
12

This page last modified on: 

8/21/2026