Skip to content

typecast

builtin · libnexusinterp/corefcn/typecast-proprietary.cc

: y = typecast (x, class)

Reinterpret the raw bytes of x as the type named by class, leaving the underlying bit pattern untouched.

No numeric conversion takes place: the in-memory bytes of x are copied verbatim and then viewed as elements of class, so the element count of y changes whenever the source and target types differ in width. For instance a scalar double occupies eight bytes and becomes a 1-by-2 uint32 array, while two uint32 values become one double. In MATLAB mode x must be a full real numeric array and class one of the integer classes, single, or double. In the Octave dialect (dialect("octave"), --dialect octave, or a %#dialect: octave header) character arrays are also accepted as x, and "char" is accepted as class so bytes can be reinterpreted as a character array (nexus#12915); MATLAB mode refuses both directions, matching R2026a (char() / uint8() / native2unicode / unicode2native instead). The total number of bytes in x must divide evenly into the size of the target element, otherwise an error is raised. The result is a row vector when x is a row and a column vector otherwise. Because it exposes the host byte order, the output of typecast is platform dependent.