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.
ValueSng()
Method
Product:
Class:
Retrieves the value of a variable defined as a single-precision (32-bit) floating-point number.
Syntax
Parameters
Return
float
Returns a Single precision value
Remarks
This method provides direct, high-performance access to the value of a variable that was explicitly defined with the Single data type.
🎯 Purpose and Use Cases
A single-precision float uses 32 bits of memory, offering a balance between range and precision that is suitable for many applications. It is particularly useful in memory-sensitive scenarios where the full 64-bit precision of a Double is unnecessary, such as:
- Storing large arrays of 3D coordinates in graphics or game development.
- Processing large batches of sensor or signal data.
- Any situation where memory usage can be halved by reducing floating-point precision without a significant impact on accuracy.
This is the getter counterpart to the setter method, which takes a float as an argument (e.g., .ValueSng(1.23)).
💡 Comparative Analysis
vs. Native Type Casting (e.g., C#
(float)obj): In native languages, you often cast a genericobjectorvariantto the desired type, which can lead to runtime errors if the cast is invalid. uCalc's Item provides a type-safe accessor. CallingValueSng()on an Item that is not of typeSinglewill not perform an implicit conversion.vs.
uc.EvalStr("MyVar"): Retrieving a value via EvalStr involves a multi-step process: the engine must look up the symbol name, evaluate it, and format the result as a string. In contrast,myItem.ValueSng()is a direct memory access operation, making it significantly faster and the preferred method for performance-critical code, especially within loops.vs. Direct Memory Binding: For ultimate performance, the DefineVariable method allows you to bind a uCalc variable directly to the memory address of a variable in your host application (e.g., via pointers in C++ or an
unsafecontext in C#). When a variable is bound this way, its value is always synchronized with the host, making explicit calls toValueSng()unnecessary.ValueSng()remains the best practice for safe, programmatic access when direct memory binding is not used.