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:
An overview of the main uCalc class, the central component for parsing, evaluation, and customization.
The uCalc class is the heart of the library. An instance of this class represents a complete, sandboxed evaluation engine with its own isolated set of variables, functions, operators, and settings. It serves as the primary factory and context for all parsing and transformation operations.
Think of a uCalc object as a self-contained language environment. You can create multiple instances, each with a different configuration, allowing you to run different parsers side-by-side without interference. This is the starting point for nearly everything you will do with the library.
These methods are the workhorses for processing expression strings.
| Member | Description |
|---|---|
Eval | Parses and evaluates a string expression in a single step, returning a numeric result. |
EvalStr | Parses and evaluates an expression in a single step, returning the result of any data type as a string. |
Parse | Compiles a string expression into an intermediate, reusable object for high-performance evaluation. |
These methods allow you to extend the engine's syntax and define data at runtime.
| Member | Description |
|---|---|
Define | Creates functions, operators, variables, and other symbols using a single, versatile definition string. |
DefineFunction | Registers a user-defined function for use in expressions, supporting inline definitions, external callbacks, and advanced features like overloading, recursion, bootstrapping, variadic args, lazy argument evaluation, and more. |
DefineOperator | Defines a custom operator to extend or modify the expression syntax at runtime. |
DefineVariable | Defines a new variable or array within the uCalc engine, with an optional initial value and data type. |
DefineConstant | Defines a named, read-only constant for use in expressions. |
CreateAlias | Creates a new symbol that behaves exactly like an existing symbol. |
These members control the creation, cloning, and destruction of uCalc engine instances.
| Member | Description |
|---|---|
Constructor | Creates a new uCalc instance, optionally cloning an existing one, or creating an empty placeholder. |
Clone | Creates an identical, but independent, copy of the current uCalc instance, including all its defined variables, functions, and settings. |
Release | Explicitly releases a uCalc instance and frees all of its associated memory and resources. |
Owned | Manages automatic resource release for an object, enabling RAII-style lifetime management primarily for C++. |
DefaultInstance | Gets/sets the globally accessible default uCalc instance. |
IsDefault | Gets or sets whether the current uCalc instance is the active default for the current thread. |
DefaultClear | Resets the default instance stack, restoring the original default instance to its initial state. |
DefaultCount | Gets the number of uCalc instances currently on the default instance stack. |
ResetAll | Resets the entire uCalc library to its initial startup state, releasing all instances and clearing all definitions. |
These members allow you to query the state and symbols within a uCalc instance.
| Member | Description |
|---|---|
ItemOf | Retrieves the uCalc.Item object for a symbol by its name, optionally filtered by properties to disambiguate overloads. |
Items | Retrieves a collection of all defined symbols (functions, variables, operators, etc.). |
DataTypeOf | Retrieves the DataType object associated with a specific item name, type name, or expression. |
DataTypes | Retrieves a collection of all data types registered within the current uCalc instance. |
Properties | Creates a bitmask for querying items by their properties, such as function, operator, or variable. |
Description | Retrieves or assigns a user-defined text description to a uCalc object, useful for attaching metadata and for debugging. |
Error | Provides access to the ErrorInfo object with details about the last error. |
These members provide access to the engines that control syntax and output formatting.
| Member | Description |
|---|---|
ExpressionTransformer | Returns the singleton transformer instance used to pre-process expressions before they are parsed. |
TokenTransformer | Retrieves the dedicated transformer for defining token-level transformations, enabling custom syntax like string interpolation or hex literals. |
ExpressionTokens | Retrieves the token definition collection used by the expression parser, allowing for inspection and customization. |
TransformerForRulePatterns | Retrieves a singleton transformer that pre-processes pattern definition strings before they are compiled into rules. |
TransformerForRuleReplacements | Retrieves a meta-transformer that pre-processes the replacement strings of other transformer rules before they are defined. |
Format | Defines a declarative rule for transforming the string output of evaluation functions. |
FormatRemove | Removes one or all custom output formatting rules previously defined with the Format method. |
DefaultDataType | Gets or sets the default data type used for implicit typing during definitions and evaluation. |
These methods create instances of other major uCalc components.
| Member | Description |
|---|---|
NewString | Creates a new uCalc.String object. |
NewTransformer | Creates a new Transformer object. |
These members are for advanced use cases, performance tuning, and debugging.
| Member | Description |
|---|---|
Handle | Returns the internal handle of the uCalc instance, a unique identifier used by the library for low-level operations. |
MemoryIndex | Returns a stable, session-unique integer that identifies a uCalc object, primarily for diagnostics and tracking object lifetimes. |
DiagMem | Provides a programmatic way to query uCalc's internal memory usage. |
ValueAt | Dereferences a pointer and returns a string representation of the value, allowing for on-the-fly type casting. |
ID: 1296
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("x = 10");
uc.DefineFunction("DoubleThis(n) = n * 2");
Console.WriteLine(uc.Eval("DoubleThis(x) + 5"));
25 using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("x = 10"); uc.DefineFunction("DoubleThis(n) = n * 2"); Console.WriteLine(uc.Eval("DoubleThis(x) + 5"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("x = 10");
uc.DefineFunction("DoubleThis(n) = n * 2");
cout << uc.Eval("DoubleThis(x) + 5") << endl;
}
25 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 10"); uc.DefineFunction("DoubleThis(n) = n * 2"); cout << uc.Eval("DoubleThis(x) + 5") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x = 10")
uc.DefineFunction("DoubleThis(n) = n * 2")
Console.WriteLine(uc.Eval("DoubleThis(x) + 5"))
End Sub
End Module
25 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x = 10") uc.DefineFunction("DoubleThis(n) = n * 2") Console.WriteLine(uc.Eval("DoubleThis(x) + 5")) End Sub End Module
ID: 271
using uCalcSoftware;
var uc = new uCalc();
// --- Main Application Context ---
// Starting with the 'uc' object as the initial default.
uCalc.DefaultInstance.DefineConstant("PI = 3.14159");
Console.WriteLine($"Initial Count: {uCalc.DefaultCount}");
// --- A Plugin needs a temporary, isolated context ---
using (var moduleCalc = new uCalc()) {
moduleCalc.IsDefault = true; // Push the new instance onto the stack.
Console.WriteLine($"Count after module pushes new default: {uCalc.DefaultCount}");
// The module's context is now active.
// uCalc::DefaultInstance() would now return 'moduleCalc'.
}
// When 'moduleCalc' goes out of scope, it's destroyed and automatically
// removed from the stack, restoring the previous default.
Console.WriteLine($"Count after module instance is disposed: {uCalc.DefaultCount}");
// Verify the original default instance is active again.
var result = uCalc.DefaultInstance.EvalStr("PI");
Console.WriteLine($"Original context restored. PI = {result}");
Initial Count: 1
Count after module pushes new default: 2
Count after module instance is disposed: 1
Original context restored. PI = 3.14159 using uCalcSoftware; var uc = new uCalc(); // --- Main Application Context --- // Starting with the 'uc' object as the initial default. uCalc.DefaultInstance.DefineConstant("PI = 3.14159"); Console.WriteLine($"Initial Count: {uCalc.DefaultCount}"); // --- A Plugin needs a temporary, isolated context --- using (var moduleCalc = new uCalc()) { moduleCalc.IsDefault = true; // Push the new instance onto the stack. Console.WriteLine($"Count after module pushes new default: {uCalc.DefaultCount}"); // The module's context is now active. // uCalc::DefaultInstance() would now return 'moduleCalc'. } // When 'moduleCalc' goes out of scope, it's destroyed and automatically // removed from the stack, restoring the previous default. Console.WriteLine($"Count after module instance is disposed: {uCalc.DefaultCount}"); // Verify the original default instance is active again. var result = uCalc.DefaultInstance.EvalStr("PI"); Console.WriteLine($"Original context restored. PI = {result}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// --- Main Application Context ---
// Starting with the 'uc' object as the initial default.
uCalc::DefaultInstance().DefineConstant("PI = 3.14159");
cout << "Initial Count: " << uCalc::DefaultCount() << endl;
// --- A Plugin needs a temporary, isolated context ---
{
uCalc moduleCalc;
moduleCalc.Owned(); // Causes moduleCalc to be released when it goes out of scope
moduleCalc.IsDefault(true); // Push the new instance onto the stack.
cout << "Count after module pushes new default: " << uCalc::DefaultCount() << endl;
// The module's context is now active.
// uCalc::DefaultInstance() would now return 'moduleCalc'.
}
// When 'moduleCalc' goes out of scope, it's destroyed and automatically
// removed from the stack, restoring the previous default.
cout << "Count after module instance is disposed: " << uCalc::DefaultCount() << endl;
// Verify the original default instance is active again.
auto result = uCalc::DefaultInstance().EvalStr("PI");
cout << "Original context restored. PI = " << result << endl;
}
Initial Count: 1
Count after module pushes new default: 2
Count after module instance is disposed: 1
Original context restored. PI = 3.14159 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // --- Main Application Context --- // Starting with the 'uc' object as the initial default. uCalc::DefaultInstance().DefineConstant("PI = 3.14159"); cout << "Initial Count: " << uCalc::DefaultCount() << endl; // --- A Plugin needs a temporary, isolated context --- { uCalc moduleCalc; moduleCalc.Owned(); // Causes moduleCalc to be released when it goes out of scope moduleCalc.IsDefault(true); // Push the new instance onto the stack. cout << "Count after module pushes new default: " << uCalc::DefaultCount() << endl; // The module's context is now active. // uCalc::DefaultInstance() would now return 'moduleCalc'. } // When 'moduleCalc' goes out of scope, it's destroyed and automatically // removed from the stack, restoring the previous default. cout << "Count after module instance is disposed: " << uCalc::DefaultCount() << endl; // Verify the original default instance is active again. auto result = uCalc::DefaultInstance().EvalStr("PI"); cout << "Original context restored. PI = " << result << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// --- Main Application Context ---
'// Starting with the 'uc' object as the initial default.
uCalc.DefaultInstance.DefineConstant("PI = 3.14159")
Console.WriteLine($"Initial Count: {uCalc.DefaultCount}")
'// --- A Plugin needs a temporary, isolated context ---
Using moduleCalc As New uCalc()
moduleCalc.IsDefault = true '// Push the new instance onto the stack.
Console.WriteLine($"Count after module pushes new default: {uCalc.DefaultCount}")
'// The module's context is now active.
'// uCalc::DefaultInstance() would now return 'moduleCalc'.
End Using
'// When 'moduleCalc' goes out of scope, it's destroyed and automatically
'// removed from the stack, restoring the previous default.
Console.WriteLine($"Count after module instance is disposed: {uCalc.DefaultCount}")
'// Verify the original default instance is active again.
Dim result = uCalc.DefaultInstance.EvalStr("PI")
Console.WriteLine($"Original context restored. PI = {result}")
End Sub
End Module
Initial Count: 1
Count after module pushes new default: 2
Count after module instance is disposed: 1
Original context restored. PI = 3.14159 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// --- Main Application Context --- '// Starting with the 'uc' object as the initial default. uCalc.DefaultInstance.DefineConstant("PI = 3.14159") Console.WriteLine($"Initial Count: {uCalc.DefaultCount}") '// --- A Plugin needs a temporary, isolated context --- Using moduleCalc As New uCalc() moduleCalc.IsDefault = true '// Push the new instance onto the stack. Console.WriteLine($"Count after module pushes new default: {uCalc.DefaultCount}") '// The module's context is now active. '// uCalc::DefaultInstance() would now return 'moduleCalc'. End Using '// When 'moduleCalc' goes out of scope, it's destroyed and automatically '// removed from the stack, restoring the previous default. Console.WriteLine($"Count after module instance is disposed: {uCalc.DefaultCount}") '// Verify the original default instance is active again. Dim result = uCalc.DefaultInstance.EvalStr("PI") Console.WriteLine($"Original context restored. PI = {result}") End Sub End Module
ID: 161
using uCalcSoftware;
var uc = new uCalc();
// In C# and VB you should use "using".
// In C++ you can flag a uCalc object for
// auto-release with Owned(), or by setting
// the last parameter of the constructor to true.
uc.IsDefault = true; // Set uc as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'Original uc object'");
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Outputs: Original uc object
// Use "using" so that the object is auto-released when it it goes out of scope
using (var uCalcTemp = new uCalc()) {
uCalcTemp.IsDefault = true; // Set uCalcTemp as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'uCalcTemp object'");
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // uCalcTemp object
}
// uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Original uc object
{
/*using*/ var uCalcSticky = new uCalc(); // remains the default even after going out of scope
uCalcSticky.IsDefault = true; // Set uCalcSticky as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'uCalcSticky object'");
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Outputs: uCalcSticky object
} // The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value"));
Original uc object
uCalcTemp object
Original uc object
uCalcSticky object
uCalcSticky object using uCalcSoftware; var uc = new uCalc(); // In C# and VB you should use "using". // In C++ you can flag a uCalc object for // auto-release with Owned(), or by setting // the last parameter of the constructor to true. uc.IsDefault = true; // Set uc as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'Original uc object'"); Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Outputs: Original uc object // Use "using" so that the object is auto-released when it it goes out of scope using (var uCalcTemp = new uCalc()) { uCalcTemp.IsDefault = true; // Set uCalcTemp as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'uCalcTemp object'"); Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // uCalcTemp object } // uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Original uc object { /*using*/ var uCalcSticky = new uCalc(); // remains the default even after going out of scope uCalcSticky.IsDefault = true; // Set uCalcSticky as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'uCalcSticky object'"); Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")); // Outputs: uCalcSticky object } // The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// In C# and VB you should use "using".
// In C++ you can flag a uCalc object for
// auto-release with Owned(), or by setting
// the last parameter of the constructor to true.
uc.IsDefault(true); // Set uc as the default uCalc object
uCalc::DefaultInstance().DefineVariable("Value = 'Original uc object'");
cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Outputs: Original uc object
{
uCalc uCalcTemp;
uCalcTemp.Owned(); // Causes uCalcTemp to be released when it goes out of scope // Make uCalcTemp owned so it reverts back to uc when uCalcTemp goes out of scope
uCalcTemp.IsDefault(true); // Set uCalcTemp as the default uCalc object
uCalc::DefaultInstance().DefineVariable("Value = 'uCalcTemp object'");
cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // uCalcTemp object
}
// uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc
cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Original uc object
{
uCalc uCalcSticky; // remains the default even after going out of scope
uCalcSticky.IsDefault(true); // Set uCalcSticky as the default uCalc object
uCalc::DefaultInstance().DefineVariable("Value = 'uCalcSticky object'");
cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Outputs: uCalcSticky object
} // The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object
cout << uCalc::DefaultInstance().EvalStr("Value") << endl;
}
Original uc object
uCalcTemp object
Original uc object
uCalcSticky object
uCalcSticky object #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // In C# and VB you should use "using". // In C++ you can flag a uCalc object for // auto-release with Owned(), or by setting // the last parameter of the constructor to true. uc.IsDefault(true); // Set uc as the default uCalc object uCalc::DefaultInstance().DefineVariable("Value = 'Original uc object'"); cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Outputs: Original uc object { uCalc uCalcTemp; uCalcTemp.Owned(); // Causes uCalcTemp to be released when it goes out of scope // Make uCalcTemp owned so it reverts back to uc when uCalcTemp goes out of scope uCalcTemp.IsDefault(true); // Set uCalcTemp as the default uCalc object uCalc::DefaultInstance().DefineVariable("Value = 'uCalcTemp object'"); cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // uCalcTemp object } // uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Original uc object { uCalc uCalcSticky; // remains the default even after going out of scope uCalcSticky.IsDefault(true); // Set uCalcSticky as the default uCalc object uCalc::DefaultInstance().DefineVariable("Value = 'uCalcSticky object'"); cout << uCalc::DefaultInstance().EvalStr("Value") << endl; // Outputs: uCalcSticky object } // The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object cout << uCalc::DefaultInstance().EvalStr("Value") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// In C# and VB you should use "using".
'// In C++ you can flag a uCalc object for
'// auto-release with Owned(), or by setting
'// the last parameter of the constructor to true.
uc.IsDefault = true '// Set uc as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'Original uc object'")
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Outputs: Original uc object
'// Use "using" so that the object is auto-released when it it goes out of scope
Using uCalcTemp As New uCalc()
uCalcTemp.IsDefault = true '// Set uCalcTemp as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'uCalcTemp object'")
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// uCalcTemp object
End Using
'// uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Original uc object
If True Then
Dim uCalcSticky As New uCalc() '// remains the default even after going out of scope
uCalcSticky.IsDefault = true '// Set uCalcSticky as the default uCalc object
uCalc.DefaultInstance.DefineVariable("Value = 'uCalcSticky object'")
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Outputs: uCalcSticky object
End If '// The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object
Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value"))
End Sub
End Module
Original uc object
uCalcTemp object
Original uc object
uCalcSticky object
uCalcSticky object Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// In C# and VB you should use "using". '// In C++ you can flag a uCalc object for '// auto-release with Owned(), or by setting '// the last parameter of the constructor to true. uc.IsDefault = true '// Set uc as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'Original uc object'") Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Outputs: Original uc object '// Use "using" so that the object is auto-released when it it goes out of scope Using uCalcTemp As New uCalc() uCalcTemp.IsDefault = true '// Set uCalcTemp as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'uCalcTemp object'") Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// uCalcTemp object End Using '// uCalcTemp goes out of scope here, and the default uCalc object reverts back to uc Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Original uc object If True Then Dim uCalcSticky As New uCalc() '// remains the default even after going out of scope uCalcSticky.IsDefault = true '// Set uCalcSticky as the default uCalc object uCalc.DefaultInstance.DefineVariable("Value = 'uCalcSticky object'") Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) '// Outputs: uCalcSticky object End If '// The uCalcSticky object itself goes out of scope here, but internally it remains the default uCalc object Console.WriteLine(uCalc.DefaultInstance.EvalStr("Value")) 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