Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Floating point arithmetics in C/C++

Name: Anonymous 2013-07-14 1:36

What's the biggest value that a float can hold while still preserving 1.0 of precision?

e.g. suppose I have:

float l = xxxxx;
l += 1.0;

If xxxxx is large enough, the second line (l += 1.0) won't change it's value, due to the nature of floating point arithmetics. My question is: how big xxxxx must be for this to happen?

And I know that the C++ standard isn't clear in regards to the size of each data type, but let's assume that sizeof(float) is 4 bytes or 32 bits, and that the IEEE standard on floating point arithmetics is followed (as occurs in g++/VC++).

This is relevant for me since I am writing an Minecraft clone, and I want to know how big can the map be before the whole thing crashes spectacularly (each block is 1x1x1).

Name: Anonymous 2013-07-14 1:40

>>1
Don't use floats for coordinates for this reason. Even if you avoid the problem you are mentioning here, you will still have an uneven distribution of coordinates. You'll see weird rounding errors occurring near the edge of the map.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List