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

Pages: 1-

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.

Name: Anonymous 2013-07-14 1:40

Do the math you idiot; it's not even that hard. If you can't solve a problem this simple, then you aren't going to be writing shit.

Name: Anonymous 2013-07-14 1:42

>>2
It's necessary to use floats since I am using real-time raytracing to render the map

Name: Anonymous 2013-07-14 1:44

Incredible graphics at an 160x120 resolution at my P4 3GHz!
And to get to standard nowadadays fullscreen resolution, only need 10x faster processor!

Name: Anonymous 2013-07-14 2:09

yo, it's 8388608

Name: Anonymous 2013-07-14 2:11

>>4
Well then I guess you're fucked.

Name: Anonymous 2013-07-14 2:14

Thanks!
Here's an screenshot of the project, that I call GBMine because of the very low resolution that I use for it to run smooth on my outdated computer (actually smaller than the Game Boy screen!)
http://i43.tinypic.com/2ewkvwj.jpg

Name: Anonymous 2013-07-14 7:41

>>1
if you use the (x/z,y/z) co-ordinate trick, you could get rid of all the rays that don't hit anything? like a Bounce Trace or something =)

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