1

I understand that there can be a .000000000000001 margin of error for double math and this is be made worse by multiplication to make the margin of error larger. With that said, is it possible to round off every calculation to a significant digit (maybe 4 decimal places) to achieve consistency across all platforms? Would it simply be more efficient using decimal math or will decimal math require similar rounding?

I will be using this for my lockstep RTS game which requires a deterministic physics engine for synchronous multiplayer. I'm using C#. Some calculations and some calculations I wish to perform include Sqrt, Sin, and Pow of the System.Math library.

JPtheK9
  • 275
  • 2
  • 12
  • Sqrt, Sin, and some Power calculations have irrational results, and so will require rounding for any finite number representation. – Patricia Shanahan Feb 10 '15 at 08:02
  • I see. Will this rounding be accurate enough to fit in snugly into 4 decimal places? – JPtheK9 Feb 10 '15 at 18:14
  • Not necessarily. If a result is very close to half way between two 4 decimal place numbers, the minimum possible difference can change which is closer. You may be better off keeping as much precision as possible internally, but displaying numbers with rounding. Still no guarantees. – Patricia Shanahan Feb 10 '15 at 20:36
  • I need for all the calculations to be the same so the errors don't accumulate. I can manage with 2 decimals, even just 1. – JPtheK9 Feb 10 '15 at 22:32
  • Reread my comment above, replacing "4 decimal place numbers" with "2 decimal place numbers". Maybe you will get lucky, and the C# implementations you are using happen to do everything exactly the same way on all the systems involved. – Patricia Shanahan Feb 11 '15 at 00:09
  • Some research told me that doubles have ~16 digits (give or take in decimal) of accuracy. Does the 4 decimal digits relate at all to this? – JPtheK9 Feb 11 '15 at 00:14

1 Answers1

0

I've actually been thinking about the whole matter in the wrong way. Instead of trying to minimize errors with greater accuracy (and more overhead), I should just use a type that stores and operates deterministically. I used the answer here: Fixed point math in c#? which helped me create a fixed point type that works perfectly and efficiently.

Community
  • 1
  • 1
JPtheK9
  • 275
  • 2
  • 12