Cast

Cast[val,type]

converts val to the type type, for use in compiled code.

Cast[val,type,"BitCast"]

reinterprets the bits representing val as having the type type.

Details

  • Cast is only available in compiled code.
  • Cast[val,type,"BitCast"] behaves as though val is written to memory and read back as type.
  • The input type to a bitcast must be the same length as the output type.

Examples

open allclose all

Basic Examples  (2)

Cast an "Integer64" to a "Real64" in a compiled function:

Cast an expression to a packed array, suitable for use with other compiled functions:

Some expressions cannot be converted into packed arrays:

Scope  (1)

Bitcast a pointer to an integer:

Wolfram Research (2022), Cast, Wolfram Language function, https://reference.wolfram.com/language/ref/Cast.html.

Text

Wolfram Research (2022), Cast, Wolfram Language function, https://reference.wolfram.com/language/ref/Cast.html.

CMS

Wolfram Language. 2022. "Cast." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Cast.html.

APA

Wolfram Language. (2022). Cast. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Cast.html

BibTeX

@misc{reference.wolfram_2022_cast, author="Wolfram Research", title="{Cast}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Cast.html}", note=[Accessed: 09-August-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_cast, organization={Wolfram Research}, title={Cast}, year={2022}, url={https://reference.wolfram.com/language/ref/Cast.html}, note=[Accessed: 09-August-2022 ]}