Function |to_i16

conv/i32::|to_i16


Usage

|to_i16(value, truncate, or_default)

Parameters

↳ value: i32
↳ truncate: bool
↳ or_default: i16

Return

i16


Turns i32 into i16.

As this conversion might be lossy (every possible i32 value cannot fit into i16), truncate allows value to be truncated to fit into a i16, and or_default set the value that is assigned when a i32 is out of range for i16 and truncation not allowed.

Truncation happens on the binary level, thus: 10010110 (150 if unsigned, -106 if signed) → 0110 (6).