strictfp for multiplayer games?

This question is bothering me for a while now. A Java VM should behave exactly the same on different platforms and hardware!? I believe that includes integer and floating point operations as well? A floating point multiplication will always return the same result no matter where it is executed? Correct?

“strictfp” implies otherwise? float might get treated differently on different platforms? I don’t get it ???

I am asking because it is somewhat relevant to multiplayer gaming. Let’s assume I have the same game state on multiple machines which I try to keep in sync. If these game states contain floating point variables, updating these floating point variables over time might result in different float values? E.g. one being 2.300000, the other 2.299999?

Do I need to use strictfp for all my float variables in the data model? Any experiences? Examples?

Don’t bother. ‘regular’ floating-point accuracy is more that enough.

Unless your calculations have intermediate values that are flirting with +/-(Double|Float).MAX_VALUE, strictfp won’t make any difference. Thems be some seriously big/small numbers.

edit: whoops, should have been -MAX_VALUE, rather than MIN_VALUE

So, there is not difference unless I am in the MIN_VALUE/MAX_VALUE area? Seems every reference indicates possible differences:

From memory, the JVM guarantees math calculation uniformity across all hardware and OS’s etc up to a threshold, so calc’s will basically be the same, but maybe not for the last couple of decimal places. Strictfp makes those last couple of decimal places exactly the same across all JVM’s.

This seems consistent with your wikipedia link definition.

Syncing simulations where physics is concerned seems to require strictfp, I’ve tried it without and tiny differences add up - thats assuming your syncing via inputs rather than state.

Kev

Hmmm, yeah. The documentation seems to suggest that it only makes a difference if there’s under or overflow, but I don’t see why the extra precision wouldn’t make a difference in all calculations, however slight it may be.

If you want to do a deterministic / lockstep simulation then those tiny differences are going to add up fast. You’ll likely find they’ll diverge rapidly.