Typecast

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1715
Joined: Sat Feb 23, 2008 11:15 pm

Typecast

Post by Kjell » Fri Feb 11, 2011 2:14 pm

8)

For people wondering how this ( the library ) would even be possible in ZGE. There's a "oddity" in the compiler that you can exploit to cast integers to floats ( and vice versa ).

For example, when assigning a hex-value to a float normally, the value gets converted from a integer to a float.

Code: Select all

float x = 0x3eaaaaab; // x = 1051372224
However, in conditional assignments the data type is determined by the first variable, which allows you to force a bit-string to be interpreted as float.

Code: Select all

float x = 0 ? 0f : 0x3eaaaaab; // x = 1/3
K

Post Reply