ValueInt16(int16)

Method

Sets the value of a uCalc variable defined as a 16-bit integer (signed or unsigned).

Product: 

Class: 

Warning

uCalc API Preview Release Notice:The uCalc engine has successfully transitioned to modern cross-platform environments.The next phase envolves some structural changes, performance optimizations, and API refinements.The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.

Syntax

ValueInt16(int16)

Parameters

value
int16
The 16-bit integer value to assign to the variable.

Return

void

Remarks

This method provides a direct and type-safe way to set the value of a uCalc variable that has been defined as a 16-bit integer (Int16 or Int16u).

It is more efficient than the generic Item.Value(string) setter because it avoids the overhead of parsing and evaluating a string expression.

Signed and Unsigned Handling

This method accepts a signed 16-bit integer. When the target uCalc variable is defined as unsigned (Int16u), the bit pattern of the input value is reinterpreted. For example, passing -1 (which is 0xFFFF in two's complement) to an unsigned variable will result in the value 65535.

⚙️ Comparative Analysis

  • vs. Item.Value(string): Using myVar.Value("123") involves the parser, which is flexible but slower. ValueInt16(123) is a direct memory operation and should be preferred in performance-critical code where the type is known.
  • vs. Native Assignment: In C# or C++, you would simply use myVar = 123;. In uCalc, interaction is through the Item object, which acts as a proxy to the engine's internal state. This method is the uCalc equivalent of that direct assignment for 16-bit integers.

Use this method after creating a variable with DefineVariable.

Examples

This page last modified on: 

8/21/2026