Skip to content

Instantly share code, notes, and snippets.

@T-Dark0
T-Dark0 / what_as_does.md
Last active November 18, 2024 15:43
What `as` does

as does a huge number of things. Probably too many. Here's a comprehensive list of everything it can do. Entries in italics are the names of functions that actually exist in the standard library, while all entries attempt to have a descriptive name for what a function that does the same thing as that particular as would do.

  • int <-> int
    • zero_extend: unsigned int -> bigger unsigned int. Pads the number with leading zeroes. This preserves the numeric value.
    • sign_extend: signed int -> bigger signed int. Pads the number with leading zeroes if positive, and leading ones if negative. This preserves the numeric value.
    • truncate: bigger int -> smaller int (regardless of signedness). Throws away the high bits of the number.
    • reinterpret_sign: int -> int of the same size and opposite signedness. Does nothing to the bits.
  • int <-> float
  • cast_saturate_to_infinity: Yields the float closest to the specified integer. Yields infinity if the integer is out of boun