FYI: Type punning like this doesn't work on all compilers i = * ( long * ) &y; // evil floating point bit level hacking Learned this recently with Arm AC6. [Also, this kind of genius analytic approximation of hot functions that do math makes me all tingly]
Would a union do the trick?
union { int i; float f } u { .f = 1.23f };
int i = u.i;
Another way is a memcpy, which I believe is the most defined way to do type punning int i;
float f;
memcpy(&i, &f, 4);
But you also have to assume the size of those primitive types but that's pretty safe in modern C/C++.