uCalc API Version: 2.1.3-preview.2 Released: 6/16/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.
(Constructor)
Constructor
Product:
Class:
Creates a new data type definition within a uCalc instance or an empty placeholder.
Remarks
⚙️ uCalc.DataType Constructor
The DataType constructor is the primary mechanism for defining custom data types at runtime within a uCalc instance. While you often retrieve existing types using methods like uCalc.DataTypeOf, this constructor allows you to extend the engine with new types or create aliases for existing ones.
This is functionally equivalent to calling uCalc.Define with a DataType: command string.
Constructor Overloads
1. DataType(string Definition)
This is the main constructor for creating a new data type. The Definition string follows a specific syntax:
DataType: NewTypeName : BaseTypeName
DataType:: A required keyword indicating the type of definition.NewTypeName: The name for your new data type.:: A required separator.BaseTypeName: The existing, built-in uCalc type that your new type inherits from (e.g.,Integer_32,Double,String).
2. DataType(uCalc uc, string Definition)
Creates the data type within a specific uCalc instance rather than the default one.
3. DataType(DataType::Empty)
Creates an empty placeholder DataType object. This is useful for deferred initialization where you can create a variable to hold the type and assign a full definition to it later.
💡 Comparative Analysis: Why uCalc?
In statically-typed languages like C# or C++, types are defined at compile time. You cannot create a new class or struct while the program is running.
uCalc's key advantage is dynamism. The DataType constructor allows your application to define new types at runtime, based on configuration files, user input, or other dynamic conditions. This is fundamental for building:
- Domain-Specific Languages (DSLs): Create types that are meaningful to your domain (e.g.,
Currency,Coordinate,ProductID) to make expressions more readable and self-documenting. - Adaptable Systems: Allow end-users to define their own data structures within a scripting environment.
- Type Aliasing: Simplify complex type names with shorter, more convenient aliases.
This runtime extensibility provides a level of flexibility that is impossible to achieve with a compiled, static type system.
Examples
Getting data type object with DataTypeOf
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name);
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize);
255
65535
true
-1
int8u
4 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_8u).Name() << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_32).ByteSize() << endl;
}
255
65535
true
-1
int8u
4 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_8u).Name() << endl; cout << uc.DataTypeOf(BuiltInType::Integer_32).ByteSize() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name)
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize)
End Sub
End Module
255
65535
true
-1
int8u
4 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize) End Sub End Module
Returning the data type of an expression
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name);
Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name);
Console.WriteLine(uc.DataTypeOf("3 < 10").Name);
Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name);
Console.WriteLine("---");
uc.DefineFunction("func(x) as string = 'Hello' * 3");
Console.WriteLine(uc.DataTypeOf("func").Name);
Console.WriteLine(uc.DataTypeOf("Int").Name);
Console.WriteLine(uc.DataTypeOf("NonExistantType").Name); // Empty string
Console.WriteLine(uc.DataTypeOf("&&").Name);
double
string
bool
complex
---
string
int
bool using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name); Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name); Console.WriteLine(uc.DataTypeOf("3 < 10").Name); Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name); Console.WriteLine("---"); uc.DefineFunction("func(x) as string = 'Hello' * 3"); Console.WriteLine(uc.DataTypeOf("func").Name); Console.WriteLine(uc.DataTypeOf("Int").Name); Console.WriteLine(uc.DataTypeOf("NonExistantType").Name); // Empty string Console.WriteLine(uc.DataTypeOf("&&").Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.DataTypeOf("10 + 20 - 3").Name() << endl;
cout << uc.DataTypeOf(" 'What type ' + 'is this?' ").Name() << endl;
cout << uc.DataTypeOf("3 < 10").Name() << endl;
cout << uc.DataTypeOf("5 + 7 * #i").Name() << endl;
cout << "---" << endl;
uc.DefineFunction("func(x) as string = 'Hello' * 3");
cout << uc.DataTypeOf("func").Name() << endl;
cout << uc.DataTypeOf("Int").Name() << endl;
cout << uc.DataTypeOf("NonExistantType").Name() << endl; // Empty string
cout << uc.DataTypeOf("&&").Name() << endl;
}
double
string
bool
complex
---
string
int
bool #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.DataTypeOf("10 + 20 - 3").Name() << endl; cout << uc.DataTypeOf(" 'What type ' + 'is this?' ").Name() << endl; cout << uc.DataTypeOf("3 < 10").Name() << endl; cout << uc.DataTypeOf("5 + 7 * #i").Name() << endl; cout << "---" << endl; uc.DefineFunction("func(x) as string = 'Hello' * 3"); cout << uc.DataTypeOf("func").Name() << endl; cout << uc.DataTypeOf("Int").Name() << endl; cout << uc.DataTypeOf("NonExistantType").Name() << endl; // Empty string cout << uc.DataTypeOf("&&").Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name)
Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name)
Console.WriteLine(uc.DataTypeOf("3 < 10").Name)
Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name)
Console.WriteLine("---")
uc.DefineFunction("func(x) as string = 'Hello' * 3")
Console.WriteLine(uc.DataTypeOf("func").Name)
Console.WriteLine(uc.DataTypeOf("Int").Name)
Console.WriteLine(uc.DataTypeOf("NonExistantType").Name) '// Empty string
Console.WriteLine(uc.DataTypeOf("&&").Name)
End Sub
End Module
double
string
bool
complex
---
string
int
bool Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name) Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name) Console.WriteLine(uc.DataTypeOf("3 < 10").Name) Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name) Console.WriteLine("---") uc.DefineFunction("func(x) as string = 'Hello' * 3") Console.WriteLine(uc.DataTypeOf("func").Name) Console.WriteLine(uc.DataTypeOf("Int").Name) Console.WriteLine(uc.DataTypeOf("NonExistantType").Name) '// Empty string Console.WriteLine(uc.DataTypeOf("&&").Name) End Sub End Module
Setting/retrieving default data type
using uCalcSoftware;
var uc = new uCalc();
// Check default data type
Console.WriteLine(uc.DefaultDataType.Name);
// This examples shows setting the default data type in 3
// different ways: by BuiltInType enum, DataType ojbect,
// or data type by name (string)
// Change default default data type
uc.DefaultDataType = uc.DataTypeOf(BuiltInType.Integer_16);
Console.WriteLine(uc.DefaultDataType.Name);
// Test new default (returns integers instead of double)
uc.DefineFunction("ff(x, y) = (x + y)/3");
// same as ff(x As int16, y As int16) As int16 = ...
uc.DefineFunction("gg(x) = x*100");
// same as gg(x As int16) As int16 = ...
Console.WriteLine(uc.Eval("ff(4, 12)"));
Console.WriteLine(uc.Eval("gg(6.1)"));
uc.SetDefaultDataType("Single");
Console.WriteLine(uc.DefaultDataType.Name);
// Change back to original default (double)
uc.SetDefaultDataType(BuiltInType.Float_Double);
// Verify that default is now double
Console.WriteLine(uc.DefaultDataType.Name);
double
int16
5
600
single
double using uCalcSoftware; var uc = new uCalc(); // Check default data type Console.WriteLine(uc.DefaultDataType.Name); // This examples shows setting the default data type in 3 // different ways: by BuiltInType enum, DataType ojbect, // or data type by name (string) // Change default default data type uc.DefaultDataType = uc.DataTypeOf(BuiltInType.Integer_16); Console.WriteLine(uc.DefaultDataType.Name); // Test new default (returns integers instead of double) uc.DefineFunction("ff(x, y) = (x + y)/3"); // same as ff(x As int16, y As int16) As int16 = ... uc.DefineFunction("gg(x) = x*100"); // same as gg(x As int16) As int16 = ... Console.WriteLine(uc.Eval("ff(4, 12)")); Console.WriteLine(uc.Eval("gg(6.1)")); uc.SetDefaultDataType("Single"); Console.WriteLine(uc.DefaultDataType.Name); // Change back to original default (double) uc.SetDefaultDataType(BuiltInType.Float_Double); // Verify that default is now double Console.WriteLine(uc.DefaultDataType.Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Check default data type
cout << uc.DefaultDataType().Name() << endl;
// This examples shows setting the default data type in 3
// different ways: by BuiltInType enum, DataType ojbect,
// or data type by name (string)
// Change default default data type
uc.DefaultDataType(uc.DataTypeOf(BuiltInType::Integer_16));
cout << uc.DefaultDataType().Name() << endl;
// Test new default (returns integers instead of double)
uc.DefineFunction("ff(x, y) = (x + y)/3");
// same as ff(x As int16, y As int16) As int16 = ...
uc.DefineFunction("gg(x) = x*100");
// same as gg(x As int16) As int16 = ...
cout << uc.Eval("ff(4, 12)") << endl;
cout << uc.Eval("gg(6.1)") << endl;
uc.SetDefaultDataType("Single");
cout << uc.DefaultDataType().Name() << endl;
// Change back to original default (double)
uc.SetDefaultDataType(BuiltInType::Float_Double);
// Verify that default is now double
cout << uc.DefaultDataType().Name() << endl;
}
double
int16
5
600
single
double #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Check default data type cout << uc.DefaultDataType().Name() << endl; // This examples shows setting the default data type in 3 // different ways: by BuiltInType enum, DataType ojbect, // or data type by name (string) // Change default default data type uc.DefaultDataType(uc.DataTypeOf(BuiltInType::Integer_16)); cout << uc.DefaultDataType().Name() << endl; // Test new default (returns integers instead of double) uc.DefineFunction("ff(x, y) = (x + y)/3"); // same as ff(x As int16, y As int16) As int16 = ... uc.DefineFunction("gg(x) = x*100"); // same as gg(x As int16) As int16 = ... cout << uc.Eval("ff(4, 12)") << endl; cout << uc.Eval("gg(6.1)") << endl; uc.SetDefaultDataType("Single"); cout << uc.DefaultDataType().Name() << endl; // Change back to original default (double) uc.SetDefaultDataType(BuiltInType::Float_Double); // Verify that default is now double cout << uc.DefaultDataType().Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Check default data type
Console.WriteLine(uc.DefaultDataType.Name)
'// This examples shows setting the default data type in 3
'// different ways: by BuiltInType enum, DataType ojbect,
'// or data type by name (string)
'// Change default default data type
uc.DefaultDataType = uc.DataTypeOf(BuiltInType.Integer_16)
Console.WriteLine(uc.DefaultDataType.Name)
'// Test new default (returns integers instead of double)
uc.DefineFunction("ff(x, y) = (x + y)/3")
'// same as ff(x As int16, y As int16) As int16 = ...
uc.DefineFunction("gg(x) = x*100")
'// same as gg(x As int16) As int16 = ...
Console.WriteLine(uc.Eval("ff(4, 12)"))
Console.WriteLine(uc.Eval("gg(6.1)"))
uc.SetDefaultDataType("Single")
Console.WriteLine(uc.DefaultDataType.Name)
'// Change back to original default (double)
uc.SetDefaultDataType(BuiltInType.Float_Double)
'// Verify that default is now double
Console.WriteLine(uc.DefaultDataType.Name)
End Sub
End Module
double
int16
5
600
single
double Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Check default data type Console.WriteLine(uc.DefaultDataType.Name) '// This examples shows setting the default data type in 3 '// different ways: by BuiltInType enum, DataType ojbect, '// or data type by name (string) '// Change default default data type uc.DefaultDataType = uc.DataTypeOf(BuiltInType.Integer_16) Console.WriteLine(uc.DefaultDataType.Name) '// Test new default (returns integers instead of double) uc.DefineFunction("ff(x, y) = (x + y)/3") '// same as ff(x As int16, y As int16) As int16 = ... uc.DefineFunction("gg(x) = x*100") '// same as gg(x As int16) As int16 = ... Console.WriteLine(uc.Eval("ff(4, 12)")) Console.WriteLine(uc.Eval("gg(6.1)")) uc.SetDefaultDataType("Single") Console.WriteLine(uc.DefaultDataType.Name) '// Change back to original default (double) uc.SetDefaultDataType(BuiltInType.Float_Double) '// Verify that default is now double Console.WriteLine(uc.DefaultDataType.Name) End Sub End Module
Displaying the data type of a parsed expression
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name);
Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name);
Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name);
Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name);
double
string
complex
bool using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name); Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name); Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name); Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.Parse(" 3 + 6 * 10 ").DataType().Name() << endl;
cout << uc.Parse(" 'This ' + 'is a string' ").DataType().Name() << endl;
cout << uc.Parse(" 2 + 8 * #i / 2").DataType().Name() << endl;
cout << uc.Parse(" 10 + 2 > 3").DataType().Name() << endl;
}
double
string
complex
bool #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.Parse(" 3 + 6 * 10 ").DataType().Name() << endl; cout << uc.Parse(" 'This ' + 'is a string' ").DataType().Name() << endl; cout << uc.Parse(" 2 + 8 * #i / 2").DataType().Name() << endl; cout << uc.Parse(" 10 + 2 > 3").DataType().Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name)
Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name)
Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name)
Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name)
End Sub
End Module
double
string
complex
bool Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name) Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name) Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name) Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name) End Sub End Module