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.

DataTypeOf(string)

Method

Product: 

Fast Math Parser

Class: 

uCalcBase

Retrieves the DataType object associated with a specific item name, type name, or expression.

Syntax

DataTypeOf(string)

Parameters

definition
string
A string containing a math expression, an existing item name (variable/function), or a data type name (e.g., "Int32").

Return

DataType

The DataType object corresponding to the input. Returns DataType::Empty if the input is invalid or cannot be resolved.

Remarks

The DataTypeOf method is a runtime introspection tool that resolves a string input into a DataType object.

It handles three categories of input strings:

  1. Expressions: It parses the expression (without fully evaluating it) to determine the resulting return type (e.g., "5 + 2.5" returns the Double type).
  2. Item Names: If the string matches a defined Variable or Function, it returns that item's declared data type.
  3. Type Names: If the string is a known type alias (e.g., "Int", "String", "Double"), it returns the corresponding type definition.

Comparison

Unlike C#'s typeof(T) which is resolved at compile-time, or Object.GetType() which requires an instantiated object, uCalc.DataTypeOf() operates on dynamic string definitions at runtime. This allows you to check the semantic type of a user's input string before attempting to evaluate it.

Aliases

For convenience, the string "Int" and "Integer" are treated as synonyms for "Int32".

If the input cannot be resolved to a valid type, the method returns DataType::Empty.

Examples

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


}
				
			
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
				
			
double
string
bool
complex
---
string
int

bool
Practical: Introspecting variables and functions.
				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable and a function
uc.DefineVariable("myVar As Int16 = 55");
uc.DefineFunction("myFunc(x) = x * 10.5"); // Implicitly returns Double

// Inspect their types dynamically
var typeVar = uc.DataTypeOf("myVar");
var typeFunc = uc.DataTypeOf("myFunc");

Console.WriteLine($"Variable Type: {typeVar.Name}");
Console.WriteLine($"Function Return: {typeFunc.Name}");

// Check specific properties
if (typeVar.BuiltInTypeEnum == BuiltInType.Integer_16) {
   Console.WriteLine("Variable is strictly a 16-bit integer.");
}
				
			
Variable Type: int16
Function Return: double
Variable is strictly a 16-bit integer.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // Define a variable and a function
   uc.DefineVariable("myVar As Int16 = 55");
   uc.DefineFunction("myFunc(x) = x * 10.5"); // Implicitly returns Double

   // Inspect their types dynamically
   auto typeVar = uc.DataTypeOf("myVar");
   auto typeFunc = uc.DataTypeOf("myFunc");

   cout << "Variable Type: " << typeVar.Name() << endl;
   cout << "Function Return: " << typeFunc.Name() << endl;

   // Check specific properties
   if (tf(typeVar.BuiltInTypeEnum() == BuiltInType::Integer_16)) {
      cout << "Variable is strictly a 16-bit integer." << endl;
   }
}
				
			
Variable Type: int16
Function Return: double
Variable is strictly a 16-bit integer.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable and a function
      uc.DefineVariable("myVar As Int16 = 55")
      uc.DefineFunction("myFunc(x) = x * 10.5") '// Implicitly returns Double
      
      '// Inspect their types dynamically
      Dim typeVar = uc.DataTypeOf("myVar")
      Dim typeFunc = uc.DataTypeOf("myFunc")
      
      Console.WriteLine($"Variable Type: {typeVar.Name}")
      Console.WriteLine($"Function Return: {typeFunc.Name}")
      
      '// Check specific properties
      If typeVar.BuiltInTypeEnum = BuiltInType.Integer_16 Then
         Console.WriteLine("Variable is strictly a 16-bit integer.")
      End If
   End Sub
End Module
				
			
Variable Type: int16
Function Return: double
Variable is strictly a 16-bit integer.
Internal Test: aliases and comparison logic.
				
					using uCalcSoftware;

var uc = new uCalc();
// "Int" is a synonym for Int32
Console.WriteLine(uc.DataTypeOf("Int").Name);

// Boolean logic expression returns bool type
Console.WriteLine(uc.DataTypeOf("3 < 10").Name);

// String concatenation returns string
Console.WriteLine(uc.DataTypeOf(" 'A' + 'B' ").Name);

// Complex number syntax
Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name);
				
			
int
bool
string
complex
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // "Int" is a synonym for Int32
   cout << uc.DataTypeOf("Int").Name() << endl;

   // Boolean logic expression returns bool type
   cout << uc.DataTypeOf("3 < 10").Name() << endl;

   // String concatenation returns string
   cout << uc.DataTypeOf(" 'A' + 'B' ").Name() << endl;

   // Complex number syntax
   cout << uc.DataTypeOf("5 + 7 * #i").Name() << endl;
}
				
			
int
bool
string
complex
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// "Int" is a synonym for Int32
      Console.WriteLine(uc.DataTypeOf("Int").Name)
      
      '// Boolean logic expression returns bool type
      Console.WriteLine(uc.DataTypeOf("3 < 10").Name)
      
      '// String concatenation returns string
      Console.WriteLine(uc.DataTypeOf(" 'A' + 'B' ").Name)
      
      '// Complex number syntax
      Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name)
   End Sub
End Module
				
			
int
bool
string
complex