Geosearchef
Geosearchef

Reputation: 648

Using rounding to make floating point operations deterministic

I have implemented a lockstep model using a simulation that has to be determinstic. For exact positions i use floats. Now i face the problem of them not being deterministic on every hardware / os. The simulation depends on vector maths with and scaling a few vectors each tick but also calculating exponential values.

Now I'm curious if it would be enough if I would round the floats to 4 places after the decimal point to achieve determinism, cause i only apply 5-10 operations to each float each tick.

Upvotes: 1

Views: 256

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109557

First using doubles would already decrease approximation errors a bit further. Then rounding might be just sufficiently deterministic.

Also use strictfp which does just what you intend to do.

Upvotes: 1

Related Questions