Is conversion from float to int consistent across all platforms and processor architectures?

Viewed 415

I'm working on a multiplayer game that depends so called "floating point determinism", or in other words, the result of all calculations must be exactly the same across everyone running the game. This essentially means not using IEEE 754 floating point since operations can result in different values depending on rounding modes, fused multiply-add or inverse square root instructions being used, different libc implementations, etc etc.

So I've gone and made fixed point versions of all the basic arithmetic operations and even some transcendental functions. However I'd still like to use floating point literals for configuring gameplay variables. In doing so, I end up with some code that looks like this to convert from floating point to fixed point:

explicit NetFixedPoint(float val)
{
  static const StorageType kOne = StorageType(1) << FractionalBits;
  m_Value = ((StorageType)(val * kOne));
}

Will this give me the same result across all platforms and processor architectures?

3 Answers
Related