a variable on the right hand size is definitely an expression. i think the difference is between comptime and runtime expressions, but i can only guess since it is not documented.
@as works with runtime-known values as well. It, however, does not change the underlying memory and only works for safe and unambiguous conversions. That’s why you can for example cast a u8 to a u16, but not vice versa.
Floats don’t have an unambiguous conversion to (and sometimes from) ints. Their memory representation of numbers is also wildly different from ints (see IEEE 754). Thus they have their own conversion functions, namely: @intToFloat and @floatToInt.
This makes me wonder… How would you implement the inverse square root trick in zig (check the “overview of the code” section in that link)? It involves casting a float to a long and back.
Yeah, that’s probably a better (more honest) way to put it . Thanks for the code example – you should have kept the colorful comments in the original, though.