views:

55

answers:

3

In a multiplayer game I'm developing, we have a few values that are floating point numbers. The back-end (in PHP) and the front-end (in Flash) occasionally perform the same calculations on these numbers, to minimize communication.

I am currently making sure that both sides are using 64-bit doubles, but am I safe to assume that all calculations will be the same?

For instance, what about string to float conversion - should I worry about Flash having a potentially different implementation as PHP? (If this happens, our game will go out of sync - the client will think it is in one state while the server is in another)

With some testing, it appears to be the same, but I'm just not sure. Can someone clarify this for me?

A: 

I would work under the assumption that it is indeed the same floating point code. Besides you send periodic checkpoints (frames with full data calculated instead of just deltas), right? Any small errors would be corrected during those.

Blindy
A: 

Well, if you can limit the number of significant decimal places, so you won't be exposed to rounding errors, and roll your own version of string to float conversion as well as any other methods that you suspect might have a different impact on the platforms, I think you're good.

luvieere
But limiting significant decimal places does nothing for operations such as ceil(x) where x can be 1.00000000001 or 0.9999999999
Fragsworth
+2  A: 

You can't, because different compilers can produce different code even for the same expression yet we are comparing different interpreters compiled by god knows what.

Most often you'll be fine depending on required precision but the edge cases will happen when calculating numbers that are mathematically supposed to be same but in practice not, due to different order of operations, just like trying to balance a needle on its tip. Regular updates don't change the fact that numbers will come out slightly differently in a significant way.

You should design you numeric algorithms with some error margin in mind if you want to use floats. Alternatively, you can use fixed point arithmetic just for the state where performance is likely limited by network but use floats elsewhere.

artificialidiot