Recently I came across a piece of code that uses a way of casting I found very strange. Here are too examples:
inline float asfloat(unsigned int x){
return *(float *) &x;
}
inline float asfloat(int x){
return *(float *) &x;
}
Does this way have any advantages? Wouldn't the following "much simpler" code do the same?
inline float asfloat(unsigned int x){
return (float)x;
}
inline float asfloat(int x){
return (float)x;
}