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.

ValueInt16(int16)

Method

Product: 

Fast Math Parser

Class: 

Item

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

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