Can we make an assumption about the order of magnitude of the represented values? I.E. anything that has an exponent that it larger than 15 is always close to an integer, because of the precision (although this is irrelevant, since anything > 2\^32 is cannot be represented as int anyway). Anything with an exponent smaller than 0 can never be close to an int (except to 0, which can be tested quite easily).

Hi folks!

I’m searching for a fast way to find out if a number stored in a float is near to an integer. Basically something like this:

I don’t really care about the rounding mode, the exact value of some_small_value ect. Only a heuristic is needed. I wouldn’t even mind a code that gives false negatives at times. No handling for NAN’s and denormals required as well.

To the background: The system I’m working on is quite slow when it comes to FPU stuff. It’s not soft-float but close from a performance point of view. To translate it from my system to the x86 world, imagine an FPU operation would be 5 to 10 times slower than the integer counterpart. Rounding and transfering data from and to the FPU are even slower.

So - how do I find out fast if a float is roughly representable as an integer. I need this to accelerate a function which can be done a lot quicker with whole numbers (a special case occures quite often).

Any ideas? Where are the IEEE 754 wizards? :-)

Nils