One place where I saw it is used in the implementation of Doom 3 / idTech 4 Fast Inverse Square Root .
For those unfamiliar with this algorithm, it essentially requires the processing of a floating-point number as a whole. An older version of Quake (and an earlier version) does this as follows:
float y = 2.0f;
github source
This code takes the address of the floating-point number y , sends it to a pointer to a long one (i.e., a 32-bit integer in Quake days) and decrypts it to i . He then does some incredibly weird bit-twiddling things, and vice versa.
There are two drawbacks to this. One of them is that the complicated process of addressing, filling, dereferencing leads to the fact that the value of y read from memory, and not from register 1 but on the way back. However, on Quake computers, floating point registers and whole registers were completely separate, so you pretty much had to click on memory and go back to deal with this limitation.
The second is that, at least in C ++, such casting is deeply condemned, even if you do what makes up voodoo, for example, this function. I'm sure there are more compelling arguments, but I'm not sure what it is :)
So in Doom 3, the identifier included the following bit in its new implementation (which uses a different set of bit-bits, but a similar idea):
union _flint { dword i; float f; }; ... union _flint seed; seed.i = ; double r = seed.f;
github source
Theoretically, on an SSE2 machine, this can be accessed through a single register; In practice, I'm not sure if any compiler will do it. This is still somewhat cleaner code, in my opinion, than casting games in an earlier version of Quake.
1 - ignoring the arguments of the "sufficiently advanced compiler"