You could use memcpy:
#include <memory.h>
int main() {
float f = 1.0;
int n;
memcpy( &n, &f, sizeof(f) );
}
I don't think there is an elegant solution to this, but whatever you do, I'd wrap it in a function to make it obvious what I was up to:
int FloatToInt( float f ) {
int n;
assert( sizeof(n) == sizeof(f) );
memcpy( &n, &f, sizeof(f) );
return n;
}
anon
2010-03-23 09:40:30