-
Deterministic Floating Point
Has anyone ever encountered any inconsistencies while using floating point values?
Eg:
On computer one: Math.sin(1) = 0.841470984807897
On computer two: Math.sin(1) = 0.841470984807898
I'm creating a car racing game which will have a replay system, but I need the engine to be completely deterministic. Differences like the above could quickly put it out of sync on different computer.
If this does happen, does anyone know how I could still use trigonometry functions without fear of this?
-
Senior Member
so do not accumulate these differences. instead of saving x0, and then dx1, dx2, dx3 save x0, x1, x2, x3 for every variable. then, even if you do some kind of "slow motion" replay, and it will be inaccurate inbetween, you would still have close match at control points.
-
Thats true, but it would require far more save data. I was thinking more along the lines of 1 byte holding all the key input data each frame, rather than the 10 or bytes to store state data.
If all else fails ill just save state data every few seconds, I'm sure the sim wouldn't get too far off in that time...
-
Senior Member
well somewhere down this very forum you might find a class for fractional numbers I wrote one day, which is free of floating point problems, but is also very slow maybe just rounding sin/cos somewhere on their way will help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|