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.

ValueInt16()

Method

Product: 

Class: 

Performs a direct memory read of a variable's value, reinterpreting the first 16 bits as a signed integer.

Syntax

ValueInt16()

Parameters

[None]

Return

int16

Returns a 16-bit integer

Remarks

The ValueInt16() method is a low-level, high-performance accessor that reads the value of a uCalc Item by interpreting its first 16 bits (2 bytes) of memory as a signed integer (short in C#).

⚠️ Direct Memory Interpretation

This method does not perform type checking or conversion. It is a direct memory operation.

  • Correct Usage: When called on a variable that was defined as Int16, it correctly returns the variable's value.
  • Incorrect Usage (Type Mismatch): When called on a variable of a different data type, this method performs a direct, low-level memory read. It reinterprets the first 2 bytes of the variable's stored value as a 16-bit signed integer, which can lead to unpredictable or meaningless results if the underlying data types are not compatible.
    • On an Int32: It will read the lower 16 bits of the 32-bit integer.
    • On a Double: It will read the first 2 bytes of the 8-byte floating-point representation, resulting in a value that is not numerically related to the original double.
    • On a String: It will read the first 2 bytes of the internal string object's memory (which could be part of a pointer or length field), leading to unpredictable results.

For safe, type-converting access, use ValueStr() and parse the resulting string.

💡 Comparative Analysis

This method's behavior is analogous to low-level type punning operations in other languages, designed for performance at the cost of safety.

  • vs. C++ reinterpret_cast: Functionally similar to casting a pointer of one type to a short* and dereferencing it. It's a powerful tool for performance-critical code but bypasses the type system.
  • vs. C# BitConverter.ToInt16: Similar to taking the first two bytes from another type's byte array and converting them to a short.

Use this method only when performance is critical and the data type is guaranteed.

Examples