I need to convert a 32 bit IEEE754 float to a signed Q19.12 fixed-point format. The problem is that it must be done in a fully deterministic way, so the usual (int)(f * (1 << FRACTION_SHIFT)) is not suitable, since it uses non-deterministic floating point math. Are there any “bit fiddling” or similar deterministic conversion methods?
Edit: Deterministic in this case is assumed as: given the same floating point data achieve exactly same conversion results on different platforms.
While @StephenCanon’s answer might be right about this particular case being fully deterministic, I’ve decided to stay on the safer side, and still do the conversion manually. This is the code I have ended up with (thanks to @CodesInChaos for pointers on how to do this):