Reputation: 23
Similar to this question I'm making a lockstep P2P virtual world and I've come across slack for using fixpoint instead of floats.
I tried to make a benchmark of portable floats but found out GCC doesn't support -fp-model=strict :(
Making floats act consistently across implementations is address by IEEE 754-2008 clause 11. But does the C/C++ standards reflect that?
ICC has -fimf-arch-consistency=true but that's not portable.
Is the only way to get consistency floats to use a software library?
Edit: Annex-F is IEC 60559:1989 which is equivalent to IEEE 754-1985 '11. Reproducible floating-point results', wasn't added until IEEE 754-2008 and says "A language standard should support reproducible programming." which according to WikiP means it's optional, and even then it's only reproducible when you tell it to be so.
Upvotes: 1
Views: 154
Reputation: 215173
If you stick to basic arithmetic, use standard-conformance options (-std=c11
rather than gnu11
, no bogus things like -ffast-math
), and watch out for a bunch of other subtleties, float
arithmetic is entirely deterministic and consistent on all Annex-F-conforming implementations where float_t
is float
, and likewise for double
on implementations where double_t
is double
. That's a lot of constraints, and the last ones ("no excess precision") may not be possible to satisfy at all without softfloat.
Whoever is giving you a hard time for using fixed point is just wrong. Floating point arithmetic is not suitable for mechanics that need to be deterministic and synchronized. Even if you satisfy all the constraints above, it's still not translation-invariant - it behaves significantly differently "away from the origin" vs "near the origin".
Floating point is perfectly good for the presentation layer. Use it there. For the mechanics/simulation layer, don't.
Upvotes: 2