piqnt / planck.js

2D JavaScript Physics Engine
http://piqnt.com/planck.js/
MIT License
4.85k stars 236 forks source link

clarification on the determinism limitation from docs #271

Open mreinstein opened 5 months ago

mreinstein commented 5 months ago

The docs state:

For the same input, and same binary, Box2D/Planck.js will reproduce any simulation.

People often want to know if Box2D/Planck.js can produce identical results on different binaries and on different platforms. The answer is no. The reason for this answer has to do with how floating point math is implemented in many compilers and processors.

I remember seeing this same limitation listed in Box2D's docs, but I'm wondering if this was intentional or incidental copying? I would think that given this is a javascript implementation, there's not really a notion of a different "binary". Or is binary/platform in this case referring to the particular browser engine?

Ultimately what I'm trying to understand is if i I ship a networked application with an embedded version of chrome, and every app has this v8 version, is that considered the same binary, such that I can expect determinism?

shakiba commented 5 months ago

The library code is deterministic, however as you pointed the result depends on how floating point math is implemented where the library code runs. We need to updating the wording in the documentation and replace "binary" with "javascript runtime".

If two runtimes have the same floating point implementation I would expect the same result.