S
Stein Gulbrandsen
What is the best way to get to the integer representation of a float?
I would like to do
int& toIntByCast (float& a) {return *reinterpret_cast<int*> (&a);}
but is this legal?
Is this safer?
int toIntByUnion (const float& a) {
union {float f; int i;} u = {a};
return u.i;
}
Or are there better ways?
I would like to do
int& toIntByCast (float& a) {return *reinterpret_cast<int*> (&a);}
but is this legal?
Is this safer?
int toIntByUnion (const float& a) {
union {float f; int i;} u = {a};
return u.i;
}
Or are there better ways?