.01f != 0.0099999998 !!!!!!!!!!

Started by
44 comments, last by Ravyne 16 years, 11 months ago
Quote:Original post by Daniel Miller
Quote:Original post by Washu
Quote:Original post by Daniel Miller
Quote:Original post by Washu
Yes, I've mentioned this in my most recent journal posting, but if you were to have one of your clients using SSE instruction sets, and another using the FPU, you can easily obtain results that differ in the least significant digits. This is due to a difference in the size of the registers used to calculate the numbers (32 bit float is widened to 80 bit on FPU, while it remains at 32 in the XMM registers).


Since I'm a noob and have no idea how to do that, would that happen by itself? Or do I have to explicitly use SSE?

If you enable SIMD instruction sets, it can happen by itself. One common case where you might find this happening would be an optimized math library that changes its behavior based on the instruction sets available on the client PC.


I am using DirectX/C#. Would that happen by itself (I wouldn't be using any 3D math, this is a 2D game). Thanks a bunch for your insight.

Assuming you are using XNA/MDX, then no. It's 32 bit only and will use just the FPU. A more portable MDX library would allow for 64 bit and 32 bit executables, in that case you could encounter it since the .NET x64 platform does use SSE2 for the majority of its floating point operations.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
Thanks. Wouldn't that make it a lot harder to design networked code? Is fixed point the common work around?
Just use a delta for comparisons.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

If you need to keep two clients in sync without a central server, is fixed point the only option?
Quote:Original post by Daniel Miller
If you need to keep two clients in sync without a central server, is fixed point the only option?


No. There's no problem with using floats, as long as you don't make assumptions that require them to be exactly perfect to X decimal places.

Does it matter if one client thinks an object is 0.0000003 metres to the left of where it actually is? If the answer to this question is "yes", then you should probably re-think your network design.
Quote:Original post by Hodgman
Quote:Original post by Daniel Miller
If you need to keep two clients in sync without a central server, is fixed point the only option?


No. There's no problem with using floats, as long as you don't make assumptions that require them to be exactly perfect to X decimal places. Does it matter if one client thinks an object is 0.0000003 metres to the left of where it actually is?


Very much so, if that causes a shot to become out of range so a unit doesn't die. That unit might kill a third unit, which would have killed a fourth unit, etc. In a RTS, things could spiral out of hand quickly.
Quote:Original post by Daniel Miller
Quote:Original post by Hodgman
Quote:Original post by Daniel Miller
If you need to keep two clients in sync without a central server, is fixed point the only option?


No. There's no problem with using floats, as long as you don't make assumptions that require them to be exactly perfect to X decimal places. Does it matter if one client thinks an object is 0.0000003 metres to the left of where it actually is?


Very much so, if that causes a shot to become out of range so a unit doesn't die. That unit might kill a third unit, which would have killed a fourth unit, etc. In a RTS, things could spiral out of hand quickly.


That should all be computed on the server, which would know the true values (since the server should be in charge of those values, not the client).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Yes, the problem is the network design, not the data types... If the network is that sensitive to faulty data, then it's a hackers dream!
Floating-point values mean fuzzy-equality, you have to use an epsilon value to determine if the the numbers are "close-enough" to be considered equal.

//integer logic
if (x==y)

//floating-point logic
static const float epsilon = 1e-5
if abs(y-x) < epsilon

I don't recall the most efficient way to code it, but that's the logic to it.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Read also this:
http://realtimecollisiondetection.net/pubs/GDC06_Ericson_Physics_Tutorial_Numerical_Robustness.ppt

talks about how to define the epsilon based on the numbers that are compated

This topic is closed to new replies.

Advertisement