Original Post
Greetings! Short question: Can i assume that the result of calculations of floating point values (float type in C#) would be the same on every computer? Like, if i run a formula that uses multiple /,*,+,- actions on a set of floating point values, would it return the same value on each of my client's PC's? Long explanation: I am programming a turn-based strategy game. The game process goes this way: 1) Turn starts 2) Every player makes its orders 3) When every player made his orders, the turn "happens" - workers produce, farmers farm, etc, population in cities grows. 4) After turn "happened" the check is made if any battles can happen. If yes, players are given options to initiate combat. Combat happens (not-involved players can chat meanwhile) 5->1)After all battles that could have happened either happened or players did not initiate, new turn starts. There is two ways of making this go in phase 1-3. a) Send complete state of player's kingdom after he finished his turn. This would make alot of data to be sent over wire that didnt actually change (player could only issue one order that changed 2 integers but whole tables of his whole fleets, units, colonies, ahivements, tech tree etc are sent). b) Send only actions of the player. So, each player action is sent over wire, and by the end of player's turn every other player knows everything that player did in his turn. Applying those changes each player's client knows exact state of other player's kingdoms they have on their client. Going the way b), i come to the way of solving phase 3. Again, there are two ways to do it: Locally and on Host. Because every player has the exact same data by the end of the turn (because he received all actions from other players) every player could have ran the "turn happens" on his own client locally. This would indeed be more fast than either getting the data from the host (host calculates and sends all the changes - like "city #5 has grown up by 10.912 people") because the amount of changes can be really big (every fleet moves, every worker produces, every farmer grows crops, every city grows new population...) So, if i want to let every player Locally calculate the effects of the turn, i must be able to trust that every PC would do the same calculations (no random gen involved here). Some of the calculations involve foating point numbers. My question is, can i trust them to be the same on every PC? For example, i have a worker that produces 10 production points per turn, a leader that increases that value by 13%, a building that increases worker's output by 20%, and some negative effect that decreases worker's output by 1/3, and i need to know how many production points did my 7 workers produce this turn, rounded to the nearest integer, would this value be the same on every PC? Or, i have a population growth formula that involves calculating some different floating point values (modifiers from 0 to 1 that show how "Full" is the current city, how "healthy" are my people, also bonuses and penaties to growth apply, it results in some multiplications and divisions of foating point numbers). Same goes for fleets moving - fleet is moving in a 2d space, its coodinate must be an integer each turn but when it moves, it can have a non-integer x or y moving vector (like a fleet with speed of 7 moves from 0,0 to 10,2) so its position must be a result of some trunctation.