You need to get to the bit representation of the float, and then:
inline unsigned int float2fint(unsigned int f) {
return f ^ ((-(f >> 31)) | 0x80000000);
}
Callahan et al. used this trick in this paper.
Caveats:
- 32-bit float only. I'm sure there are generalizations for doubles, etc.
- No idea what it does to NaN's (although I've a vague recollection that this does the right thing to denormals. I could be wrong)