Advertisement

Binary differences between CPU types and OSs (BIG headache)

Started by July 11, 2004 08:15 PM
11 comments, last by hplus0603 20 years, 7 months ago
Ok hplus0603, I did some further research and it looks like you are correct. Sorry If I came off as a bit of a know-it-all.

It's just that I have done some portable stuff with floats myself(PPC and intel, files & network) and never experienced any of these problems, so I guess I wrongly assumed that no problems were possible.
Quote:
Original post by hplus0603

Floating point has very well defined precision; as long as you stay within the precision, it is exact.


When you say "stay within the precision", do you mean, "only ever use values that floating point numbers can represent exactly"? Like, 0.1 is a value that floating points can't do exactly. The following code will NOT print "match"

float x = 0.1 + 0.1 + 0.1;if (x == 0.3)  puts("match");


which is why checking for equality on floats is Bad.
Advertisement
If you use imprecise numbers, you can only make imprecise comparisions. That's why using imprecise numbers are bad. Just because 0.1 is nice and round in decimal, doesn't mean it's a good number to use in a floating-point world.

Typically, your data editors will specify a precise, minimum quantum (say, 1.0 / 16384) and specify values as multiples of that quantum. If you do arbitrary math that isn't guaranteed to preserve precision (say, division, or transcendentals) then you need to round back to a quantum again when your physics step is done.

Or you can just accept the divergence and design for it, at the cost of higher network usage and fewer possible objects in a networked game; that's certainly easier.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement