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.

ValueAt

Method

Product: 

Fast Math Parser

Class: 

uCalcBase

Dereferences a pointer and returns a string representation of the value, allowing for on-the-fly type casting.

Syntax

ValueAt(POINTER, DataType, bool)

Parameters

valuePtr
POINTER
The memory address (pointer) of the value to retrieve.
targetType
DataType
(Default = Empty)
The DataType object or its name, used to interpret the data at the specified memory address. This allows for type casting (e.g., viewing a signed integer as unsigned).
formattedOutput
bool
(Default = false)
If `true`, the output string is formatted according to the rules defined by the Format method. Defaults to `false`.

Return

string

A string representation of the value at the given memory address, interpreted as the specified targetType.

Remarks

🎯 ValueAt: Dereference and Interpret Memory

The ValueAt method provides a powerful, low-level mechanism to dereference a pointer and retrieve the value stored at that memory address. Its primary function is to interpret raw memory as a specific data type and return its string representation. This is particularly useful for type punning, where you want to view the same block of memory as different data types.

How It Works

In languages like C/C++, you might cast a pointer to a different type to change how you interpret the data it points to. For example, *(unsigned int*)signed_int_ptr. ValueAt brings this capability into the uCalc scripting environment in a managed way.

You provide:

  1. A memory address (valuePtr).
  2. A data type (targetType) to use for interpretation.
  3. An optional flag (formattedOutput) to apply custom formatting.

The engine then reads the data at valuePtr, interprets its bits according to the rules of targetType, and converts the result to a string.

💡 Common Use Cases

  • Viewing Signed vs. Unsigned: Read an Int8 value from memory but display it as an Int8u to see its unsigned representation (e.g., -1 becomes 255).
  • Inspecting Expression Results: When an expression is parsed to return a specific type (e.g., an unsigned integer), ValueAt can be used to see what that result would be if it were a different type (e.g., a signed integer), without re-evaluating the expression.
  • Interfacing with Pointers: When working with variables defined as pointers, ValueAt is the standard way to get the value they point to.

Formatting

If formattedOutput is set to true, the resulting string will be formatted using the global format string defined by the Format method.

Examples

Retrieves a double-precision value from a pointer, with and without formatting.
				
					using uCalcSoftware;

var uc = new uCalc();
// Define a global format for the 'formattedOutput' parameter
uc.Format("Result = 'Answer: <' + Result + '>'");

// Create a variable and get its memory address
var myDouble = uc.DefineVariable("MyDouble = 123.456");
var ptr = myDouble.ValueAddr();

// 1. Retrieve the value by specifying the data type by name
Console.WriteLine($"By Name: {uc.ValueAt(ptr, "Double")}");

// 2. Retrieve the value using the built-in enum
Console.WriteLine($"By Enum: {uc.ValueAt(ptr, BuiltInType.Float_Double)}");

// 3. Retrieve the value with formatting enabled
Console.WriteLine($"Formatted: {uc.ValueAt(ptr, BuiltInType.Float_Double, true)}");
				
			
By Name: 123.456
By Enum: 123.456
Formatted: Answer: <123.456>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a global format for the 'formattedOutput' parameter
   uc.Format("Result = 'Answer: <' + Result + '>'");

   // Create a variable and get its memory address
   auto myDouble = uc.DefineVariable("MyDouble = 123.456");
   auto ptr = myDouble.ValueAddr();

   // 1. Retrieve the value by specifying the data type by name
   cout << "By Name: " << uc.ValueAt(ptr, "Double") << endl;

   // 2. Retrieve the value using the built-in enum
   cout << "By Enum: " << uc.ValueAt(ptr, BuiltInType::Float_Double) << endl;

   // 3. Retrieve the value with formatting enabled
   cout << "Formatted: " << uc.ValueAt(ptr, BuiltInType::Float_Double, true) << endl;
}
				
			
By Name: 123.456
By Enum: 123.456
Formatted: Answer: <123.456>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a global format for the 'formattedOutput' parameter
      uc.Format("Result = 'Answer: <' + Result + '>'")
      
      '// Create a variable and get its memory address
      Dim myDouble = uc.DefineVariable("MyDouble = 123.456")
      Dim ptr = myDouble.ValueAddr()
      
      '// 1. Retrieve the value by specifying the data type by name
      Console.WriteLine($"By Name: {uc.ValueAt(ptr, "Double")}")
      
      '// 2. Retrieve the value using the built-in enum
      Console.WriteLine($"By Enum: {uc.ValueAt(ptr, BuiltInType.Float_Double)}")
      
      '// 3. Retrieve the value with formatting enabled
      Console.WriteLine($"Formatted: {uc.ValueAt(ptr, BuiltInType.Float_Double, true)}")
   End Sub
End Module
				
			
By Name: 123.456
By Enum: 123.456
Formatted: Answer: <123.456>
Demonstrates type punning by interpreting an unsigned byte (`Int8u`) result as a signed byte (`Int8`) to observe how values wrap around.
				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable 'x' that will be used in our expression
var variableX = uc.DefineVariable("x As Int");

// Parse an expression that will result in an unsigned 8-bit integer (0-255)
var parsedExpr = uc.Parse("x + 125", "Int8u");

Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)");
Console.WriteLine("------------------------------------------");

for (int x = 1; x <= 5; x++) {
   variableX.ValueInt32(x);

   // Evaluate the expression to get a pointer to the result
   var resultPtr = parsedExpr.EvaluateVoid();

   // Get the raw unsigned result
   var unsignedResult = uc.ValueAt(resultPtr, "Int8u");

   // Use ValueAt to *re-interpret* the same memory as a signed byte
   var signedResult = uc.ValueAt(resultPtr, "Int8");

   Console.WriteLine($"{x} | {unsignedResult} | {signedResult}");
}

// Clean up the created items
parsedExpr.Release();
variableX.Release();
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable 'x' that will be used in our expression
   auto variableX = uc.DefineVariable("x As Int");

   // Parse an expression that will result in an unsigned 8-bit integer (0-255)
   auto parsedExpr = uc.Parse("x + 125", "Int8u");

   cout << "x | Int8u (0 to 255) | Int8 (-128 to 127)" << endl;
   cout << "------------------------------------------" << endl;

   for (int x = 1; x <= 5; x++) {
      variableX.ValueInt32(x);

      // Evaluate the expression to get a pointer to the result
      auto resultPtr = parsedExpr.EvaluateVoid();

      // Get the raw unsigned result
      auto unsignedResult = uc.ValueAt(resultPtr, "Int8u");

      // Use ValueAt to *re-interpret* the same memory as a signed byte
      auto signedResult = uc.ValueAt(resultPtr, "Int8");

      cout << x << " | " << unsignedResult << " | " << signedResult << endl;
   }

   // Clean up the created items
   parsedExpr.Release();
   variableX.Release();
}
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable 'x' that will be used in our expression
      Dim variableX = uc.DefineVariable("x As Int")
      
      '// Parse an expression that will result in an unsigned 8-bit integer (0-255)
      Dim parsedExpr = uc.Parse("x + 125", "Int8u")
      
      Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)")
      Console.WriteLine("------------------------------------------")
      
      For x  As Integer = 1 To 5
         variableX.ValueInt32(x)
         
         '// Evaluate the expression to get a pointer to the result
         Dim resultPtr = parsedExpr.EvaluateVoid()
         
         '// Get the raw unsigned result
         Dim unsignedResult = uc.ValueAt(resultPtr, "Int8u")
         
         '// Use ValueAt to *re-interpret* the same memory as a signed byte
         Dim signedResult = uc.ValueAt(resultPtr, "Int8")
         
         Console.WriteLine($"{x} | {unsignedResult} | {signedResult}")
      Next
      
      '// Clean up the created items
      parsedExpr.Release()
      variableX.Release()
   End Sub
End Module
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
Pointer value with ValueAt
				
					using uCalcSoftware;

var uc = new uCalc();
uc.Format("Result = 'Answer: <' + Result + '>'");

var Dbl = uc.DefineVariable("MyDouble = 123.456");

Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), "Double"));
Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), BuiltInType.Float_Double));
Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), BuiltInType.Float_Double, true));


				
			
123.456
123.456
Answer: <123.456>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.Format("Result = 'Answer: <' + Result + '>'");

   auto Dbl = uc.DefineVariable("MyDouble = 123.456");

   cout << uc.ValueAt(Dbl.ValueAddr(), "Double") << endl;
   cout << uc.ValueAt(Dbl.ValueAddr(), BuiltInType::Float_Double) << endl;
   cout << uc.ValueAt(Dbl.ValueAddr(), BuiltInType::Float_Double, true) << endl;


}
				
			
123.456
123.456
Answer: <123.456>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.Format("Result = 'Answer: <' + Result + '>'")
      
      Dim Dbl = uc.DefineVariable("MyDouble = 123.456")
      
      Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), "Double"))
      Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), BuiltInType.Float_Double))
      Console.WriteLine(uc.ValueAt(Dbl.ValueAddr(), BuiltInType.Float_Double, true))
      
      
   End Sub
End Module
				
			
123.456
123.456
Answer: <123.456>